Skip to content

Commit

Permalink
Fix issue 61 (#62)
Browse files Browse the repository at this point in the history
* fix: issue 61

* add: 'locked' attribute, test files and testing

* del: removed the comment
  • Loading branch information
XiangYyang authored Nov 16, 2023
1 parent da3c0a5 commit 2e21f95
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/kicad/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ export class Text {

export class FpText extends Text {
type: "reference" | "value" | "user";
locked: boolean = false;

constructor(
expr: Parseable,
Expand All @@ -1322,6 +1323,7 @@ export class FpText extends Text {
parse_expr(
expr,
P.start("fp_text"),
P.atom("locked"),
P.positional("type", T.string),
P.positional("text", T.string),
...Text.common_expr_defs,
Expand All @@ -1331,6 +1333,8 @@ export class FpText extends Text {
}

export class GrText extends Text {
locked: boolean = false;

constructor(
expr: Parseable,
public override parent: Footprint | Dimension | KicadPCB,
Expand All @@ -1342,6 +1346,7 @@ export class GrText extends Text {
parse_expr(
expr,
P.start("gr_text"),
P.atom("locked"),
P.positional("text", T.string),
...Text.common_expr_defs,
),
Expand Down
46 changes: 46 additions & 0 deletions test/kicad/board.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import properties_pcb_src from "./files/properties.kicad_pcb";
import paper_pcb_src from "./files/paper.kicad_pcb";
import shapes_pcb_src from "./files/shapes.kicad_pcb";
import text_pcb_src from "./files/text.kicad_pcb";
import text_locked_pcb_src from "./files/text-locked.kicad_pcb";
import traces_pcb_src from "./files/traces.kicad_pcb";
import dimensions_pcb_src from "./files/dimensions.kicad_pcb";
import zones_pcb_src from "./files/zones.kicad_pcb";
import vias_pcb_src from "./files/vias.kicad_pcb";
import footprint_graphics_pcb_src from "./files/footprint-graphics.kicad_pcb";
import footprint_pads_pcb_src from "./files/footprint-pads.kicad_pcb";
import footprint_text_locked_pcb_src from "./files/footprint-text-locked.kicad_pcb";
import { first } from "../../src/base/iterator";

suite("kicad.board.KicadPCB(): board parsing", function () {
Expand Down Expand Up @@ -315,6 +317,50 @@ suite("kicad.board.KicadPCB(): board parsing", function () {
} as any);
});

test("with locked gr_text", function () {
const pcb = new board.KicadPCB(
"text-locked.kicad_pcb",
text_locked_pcb_src,
);

assert.equal(pcb.drawings.length, 2);

assert.include(pcb.drawings[0], {
text: "Text locked",
locked: true,
});

assert.include(pcb.drawings[1], {
text: "Text unlocked",
locked: false,
});
});

test("with locked fp_text", function () {
const pcb = new board.KicadPCB(
"footprint-text-locked.kicad_pcb",
footprint_text_locked_pcb_src,
);

assert.equal(pcb.footprints.length, 1);

const footprint = pcb.footprints[0]!;

assert.equal(footprint.drawings.length, 2);

assert.include(footprint.drawings[0], {
text: "Locked text",
locked: true,
type: "reference",
});

assert.include(footprint.drawings[1], {
text: "Unlocked text",
locked: false,
type: "value",
});
});

test("with traces", function () {
const pcb = new board.KicadPCB("test.kicad_pcb", traces_pcb_src);

Expand Down
100 changes: 100 additions & 0 deletions test/kicad/files/footprint-text-locked.kicad_pcb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
(kicad_pcb (version 20221018) (generator pcbnew)

(general
(thickness 1.6)
)

(paper "A4")
(title_block
(date "2023-11-15")
)

(layers
(0 "F.Cu" signal)
(31 "B.Cu" signal)
(32 "B.Adhes" user "B.Adhesive")
(33 "F.Adhes" user "F.Adhesive")
(34 "B.Paste" user)
(35 "F.Paste" user)
(36 "B.SilkS" user "B.Silkscreen")
(37 "F.SilkS" user "F.Silkscreen")
(38 "B.Mask" user)
(39 "F.Mask" user)
(40 "Dwgs.User" user "User.Drawings")
(41 "Cmts.User" user "User.Comments")
(42 "Eco1.User" user "User.Eco1")
(43 "Eco2.User" user "User.Eco2")
(44 "Edge.Cuts" user)
(45 "Margin" user)
(46 "B.CrtYd" user "B.Courtyard")
(47 "F.CrtYd" user "F.Courtyard")
(48 "B.Fab" user)
(49 "F.Fab" user)
(50 "User.1" user)
(51 "User.2" user)
(52 "User.3" user)
(53 "User.4" user)
(54 "User.5" user)
(55 "User.6" user)
(56 "User.7" user)
(57 "User.8" user)
(58 "User.9" user)
)

(setup
(pad_to_mask_clearance 0)
(pcbplotparams
(layerselection 0x00010fc_ffffffff)
(plot_on_all_layers_selection 0x0000000_00000000)
(disableapertmacros false)
(usegerberextensions false)
(usegerberattributes true)
(usegerberadvancedattributes true)
(creategerberjobfile true)
(dashed_line_dash_ratio 12.000000)
(dashed_line_gap_ratio 3.000000)
(svgprecision 6)
(plotframeref false)
(viasonmask false)
(mode 1)
(useauxorigin false)
(hpglpennumber 1)
(hpglpenspeed 20)
(hpglpendiameter 15.000000)
(dxfpolygonmode true)
(dxfimperialunits true)
(dxfusepcbnewfont true)
(psnegative false)
(psa4output false)
(plotreference true)
(plotvalue true)
(plotinvisibletext false)
(sketchpadsonfab false)
(subtractmaskfromsilk false)
(outputformat 1)
(mirror false)
(drillshape 1)
(scaleselection 1)
(outputdirectory "")
)
)

(net 0 "")

(footprint "Test:FP_TEXT" (layer "F.Cu")
(tstamp ae31b982-acd4-4521-aae0-6a9cd79c651e)
(at 0 0)
(descr "Test footprint")
(tags "Test footprint")
(attr smd)
(fp_text reference locked "Locked text" (at 0 -1.43) (layer "F.SilkS")
(effects (font (size 1 1) (thickness 0.15)))
(tstamp 1fcf489e-3bc0-4c88-9d09-0ce7f3df6eeb)
)
(fp_text value "Unlocked text" (at 0 1.43) (layer "F.Fab")
(effects (font (size 1 1) (thickness 0.15)))
(tstamp 0fb908c9-7e55-4094-b31d-827bba51a0bb)
)
)

)
91 changes: 91 additions & 0 deletions test/kicad/files/text-locked.kicad_pcb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
(kicad_pcb (version 20221018) (generator pcbnew)

(general
(thickness 1.6)
)

(paper "A4")
(title_block
(date "2023-11-15")
)

(layers
(0 "F.Cu" signal)
(31 "B.Cu" signal)
(32 "B.Adhes" user "B.Adhesive")
(33 "F.Adhes" user "F.Adhesive")
(34 "B.Paste" user)
(35 "F.Paste" user)
(36 "B.SilkS" user "B.Silkscreen")
(37 "F.SilkS" user "F.Silkscreen")
(38 "B.Mask" user)
(39 "F.Mask" user)
(40 "Dwgs.User" user "User.Drawings")
(41 "Cmts.User" user "User.Comments")
(42 "Eco1.User" user "User.Eco1")
(43 "Eco2.User" user "User.Eco2")
(44 "Edge.Cuts" user)
(45 "Margin" user)
(46 "B.CrtYd" user "B.Courtyard")
(47 "F.CrtYd" user "F.Courtyard")
(48 "B.Fab" user)
(49 "F.Fab" user)
(50 "User.1" user)
(51 "User.2" user)
(52 "User.3" user)
(53 "User.4" user)
(54 "User.5" user)
(55 "User.6" user)
(56 "User.7" user)
(57 "User.8" user)
(58 "User.9" user)
)

(setup
(pad_to_mask_clearance 0)
(pcbplotparams
(layerselection 0x00010fc_ffffffff)
(plot_on_all_layers_selection 0x0000000_00000000)
(disableapertmacros false)
(usegerberextensions false)
(usegerberattributes true)
(usegerberadvancedattributes true)
(creategerberjobfile true)
(dashed_line_dash_ratio 12.000000)
(dashed_line_gap_ratio 3.000000)
(svgprecision 6)
(plotframeref false)
(viasonmask false)
(mode 1)
(useauxorigin false)
(hpglpennumber 1)
(hpglpenspeed 20)
(hpglpendiameter 15.000000)
(dxfpolygonmode true)
(dxfimperialunits true)
(dxfusepcbnewfont true)
(psnegative false)
(psa4output false)
(plotreference true)
(plotvalue true)
(plotinvisibletext false)
(sketchpadsonfab false)
(subtractmaskfromsilk false)
(outputformat 1)
(mirror false)
(drillshape 1)
(scaleselection 1)
(outputdirectory "")
)
)

(net 0 "")

(gr_text locked "Text locked" (at 0 1) (layer "Dwgs.User") (tstamp 53256d70-8bb6-458c-8ac7-948fdc9b6360)
(effects (font (size 1 1) (thickness 0.15)))
)
(gr_text "Text unlocked" (at 0 0) (layer "Dwgs.User") (tstamp 667160ac-fe18-4172-8c47-776e19652d19)
(effects (font (size 1 1) (thickness 0.15)))
)

)

0 comments on commit 2e21f95

Please sign in to comment.