Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cho45 committed Aug 8, 2017
1 parent 28b5386 commit 49bab9b
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 151 deletions.
58 changes: 58 additions & 0 deletions dist/src/kicad_common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/kicad_common.js.map

Large diffs are not rendered by default.

54 changes: 1 addition & 53 deletions dist/src/kicad_pcb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/kicad_pcb.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dist/src/kicad_plotter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/kicad_plotter.js.map

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions dist/src/kicad_sch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/kicad_sch.js.map

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions src/kicad_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,67 @@ export class Size {
constructor(public width: number, public height: number) {
}
}

export class PageInfo {
pageType: string;
width: number;
height: number;
portrait: boolean = false;

static A4 = new PageInfo("A4" , false , MM2MIL(297) , MM2MIL(210));
static A3 = new PageInfo("A3" , false , MM2MIL(420) , MM2MIL(297));
static A2 = new PageInfo("A2" , false , MM2MIL(594) , MM2MIL(420));
static A1 = new PageInfo("A1" , false , MM2MIL(841) , MM2MIL(594));
static A0 = new PageInfo("A0" , false , MM2MIL(1189) , MM2MIL(841));
static A = new PageInfo("A" , false , 11000 , 8500);
static B = new PageInfo("B" , false , 17000 , 11000);
static C = new PageInfo("C" , false , 22000 , 17000);
static D = new PageInfo("D" , false , 34000 , 22000);
static E = new PageInfo("E" , false , 44000 , 34000);
static GERBER = new PageInfo("GERBER" , false , 32000 , 32000);
static User = new PageInfo("User" , false , 17000 , 11000);
static USLetter = new PageInfo("USLetter" , false , 11000 , 8500);
static USLegal = new PageInfo("USLegal" , false , 14000 , 8500);
static USLedger = new PageInfo("USLedger" , false , 17000 , 11000);
static PAGE_TYPES = [
PageInfo.A4 ,
PageInfo.A3 ,
PageInfo.A2 ,
PageInfo.A1 ,
PageInfo.A0 ,
PageInfo.A ,
PageInfo.B ,
PageInfo.C ,
PageInfo.D ,
PageInfo.E ,
PageInfo.GERBER ,
PageInfo.User ,
PageInfo.USLetter,
PageInfo.USLegal ,
PageInfo.USLedger,
];

constructor(pageType: string, portrait: boolean = false, width?: number, height?: number) {
this.width = width || 0;
this.height = height || 0;
if (!width && !height) {
this.setPageType(pageType);
} else {
this.pageType = pageType;
}
this.setPortrait(portrait);
}

setPageType(pageType: string) {
const page = PageInfo.PAGE_TYPES.find((i) => i.pageType === pageType);
Object.assign(this, page);
this.pageType = pageType;
}

setPortrait(portrait: boolean) {
if (this.portrait != portrait) {
[this.width, this.height] = [this.height, this.width];
this.portrait = portrait;
}
}
}
60 changes: 1 addition & 59 deletions src/kicad_pcb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
TextHjustify,
TextVjustify,
RotatePoint,
PageInfo,
} from "./kicad_common";

import { Token } from "./kicad_pcb_token";
Expand Down Expand Up @@ -1537,65 +1538,6 @@ export class Board {
layerDescr: { [key: number]: Layer } = {};
}

class PageInfo {
pageType: string;
width: number;
height: number;
portrait: boolean = false;

static A4 = new PageInfo("A4" , false , MM2MIL(297) , MM2MIL(210));
static A3 = new PageInfo("A3" , false , MM2MIL(420) , MM2MIL(297));
static A2 = new PageInfo("A2" , false , MM2MIL(594) , MM2MIL(420));
static A1 = new PageInfo("A1" , false , MM2MIL(841) , MM2MIL(594));
static A0 = new PageInfo("A0" , false , MM2MIL(1189) , MM2MIL(841));
static A = new PageInfo("A" , false , 11000 , 8500);
static B = new PageInfo("B" , false , 17000 , 11000);
static C = new PageInfo("C" , false , 22000 , 17000);
static D = new PageInfo("D" , false , 34000 , 22000);
static E = new PageInfo("E" , false , 44000 , 34000);
static GERBER = new PageInfo("GERBER" , false , 32000 , 32000);
static User = new PageInfo("User" , false , 17000 , 11000);
static USLetter = new PageInfo("USLetter" , false , 11000 , 8500);
static USLegal = new PageInfo("USLegal" , false , 14000 , 8500);
static USLedger = new PageInfo("USLedger" , false , 17000 , 11000);
static PAGE_TYPES = [
PageInfo.A4 ,
PageInfo.A3 ,
PageInfo.A2 ,
PageInfo.A1 ,
PageInfo.A0 ,
PageInfo.A ,
PageInfo.B ,
PageInfo.C ,
PageInfo.D ,
PageInfo.E ,
PageInfo.GERBER ,
PageInfo.User ,
PageInfo.USLetter,
PageInfo.USLegal ,
PageInfo.USLedger,
];

constructor(pageType: string, portrait: boolean = false, width?: number, height?: number) {
this.width = width || 0;
this.height = height || 0;
if (!width && !height) {
this.setPageType(pageType);
}
this.setPortrait(portrait);
}

setPageType(pageType: string) {
const page = PageInfo.PAGE_TYPES.find((i) => i.pageType === pageType);
Object.assign(this, page);
}

setPortrait(portrait: boolean) {
if (this.portrait != portrait) {
[this.width, this.height] = [this.height, this.width];
}
}
}

export enum PCB_LAYER_ID {
UNDEFINED_LAYER = -1,
Expand Down
9 changes: 6 additions & 3 deletions src/kicad_plotter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ export abstract class Plotter {
this.errors = [];
}

startPlot(): void {}
endPlot(): void {}

abstract rect(p1: Point, p2: Point, fill: Fill, width: number): void;
abstract circle(p: Point, dia: number, fill: Fill, width: number): void;
abstract arc(p: Point, startAngle: number, endAngle: number, radius: number, fill: Fill, width: number): void;
Expand Down Expand Up @@ -1513,12 +1516,12 @@ export class SVGPlotter extends Plotter {
}

plotSchematic(sch: Schematic, libs: Array<Library>) {
const width = sch.descr.width;
const height =sch.descr.height;
const width = sch.descr.width;
const height = sch.descr.height;
this.output = this.xmlTag `<svg preserveAspectRatio="xMinYMin"
width="${width}"
height="${height}"
viewBox="0 0 ${sch.descr.width} ${sch.descr.height}"
viewBox="0 0 ${width} ${height}"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1">`;
Expand Down
23 changes: 15 additions & 8 deletions src/kicad_sch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
SheetSide,
Net,
ReadDelimitedText,
PageInfo,
} from "./kicad_common";

export enum TextOrientationType {
Expand Down Expand Up @@ -294,12 +295,9 @@ export class Field extends SchItem {
}

export class Descr {
pageType: string;
width: number;
height: number;
pageInfo: PageInfo;
screenNumber: number;
numberOfScreens: number;
orientation: number;
title: string;
date: string;
rev: string;
Expand All @@ -310,10 +308,19 @@ export class Descr {
comment4: string;

constructor(tokens: Array<string>) {
this.pageType = tokens[0];
this.width = Number(tokens[1]);
this.height = Number(tokens[2]);
this.orientation = Number(tokens[3] || 0);
let pageType = tokens[0];
let width = Number(tokens[1]);
let height = Number(tokens[2]);
let portrait = (tokens[3] || '') === 'portrait';
this.pageInfo = new PageInfo(pageType, portrait, width, height);
}

get width() {
return this.pageInfo.width;
}

get height() {
return this.pageInfo.height;
}

parse(lines: Array<string>): this {
Expand Down
Loading

0 comments on commit 49bab9b

Please sign in to comment.