Skip to content

Commit 5f16742

Browse files
committed
Generate unique IDs for all objects
1 parent 27023de commit 5f16742

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

native/src/fauxuuid.zig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const std = @import("std");
2+
const print = std.debug.print;
3+
const testing = std.testing;
4+
5+
pub const FauxUUID = struct {
6+
bytes: [16]u8,
7+
8+
pub fn init() FauxUUID {
9+
var uuid = FauxUUID{ .bytes = undefined };
10+
std.crypto.random.bytes(&uuid.bytes);
11+
return uuid;
12+
}
13+
14+
pub fn format(self: FauxUUID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
15+
_ = fmt;
16+
_ = options;
17+
18+
try writer.print("{x}-{x}-{x}-{x}-{x}", .{
19+
std.fmt.fmtSliceHexLower(self.bytes[0..4]),
20+
std.fmt.fmtSliceHexLower(self.bytes[4..6]),
21+
std.fmt.fmtSliceHexLower(self.bytes[6..8]),
22+
std.fmt.fmtSliceHexLower(self.bytes[8..10]),
23+
std.fmt.fmtSliceHexLower(self.bytes[10..16]),
24+
});
25+
}
26+
};
27+
28+
test "fauxuuid" {
29+
std.debug.print("\n{any}\n", .{FauxUUID.init()});
30+
}

native/src/pcb.zig

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const testing = std.testing;
44
const geometry = @import("geometry.zig");
55
const Poly = geometry.Poly;
66
const PolyList = geometry.PolyList;
7+
const FauxUUID = @import("fauxuuid.zig").FauxUUID;
78

89
pub fn start_pcb(writer: anytype) !void {
910
try writer.writeAll("(kicad_pcb (version 20211014) (generator pcbnew)\n");
@@ -38,7 +39,7 @@ pub fn end_xx_poly(layer: []const u8, width: f64, fill: bool, writer: anytype) !
3839
try writer.print(" (layer \"{s}\")\n", .{layer});
3940
try writer.print(" (width {d:.3})\n", .{width});
4041
try writer.print(" (fill {s})\n", .{if (fill) "solid" else "none"});
41-
try writer.writeAll(" (tstamp \"e9dc14e2-3c62-11ed-ab80-7a0c86e760e0\")\n");
42+
try writer.print(" (tstamp \"{s}\")\n", .{FauxUUID.init()});
4243
try writer.writeAll(" )\n");
4344
}
4445

@@ -57,8 +58,8 @@ pub fn polylist_to_footprint(polylist: PolyList, layer: []const u8, scale_factor
5758
try writer.print(" (layer \"{s}\")\n", .{layer});
5859
try writer.writeAll(" (at 0 0)\n");
5960
try writer.writeAll(" (attr board_only exclude_from_pos_files exclude_from_bom)\n");
60-
try writer.writeAll(" (tstamp \"e9dc178a-3c62-11ed-ab80-7a0c86e760e0\")\n");
61-
try writer.writeAll(" (tedit \"e9dc1794-3c62-11ed-ab80-7a0c86e760e0\")\n");
61+
try writer.print(" (tstamp \"{s}\")\n", .{FauxUUID.init()});
62+
try writer.print(" (tedit \"{s}\")\n", .{FauxUUID.init()});
6263

6364
for (polylist.items) |poly| {
6465
try points_to_xx_poly("fp", poly.outline, scale_factor, layer, 0, true, writer);
@@ -70,16 +71,16 @@ pub fn polylist_to_footprint(polylist: PolyList, layer: []const u8, scale_factor
7071
pub fn add_drill(x: f64, y: f64, d: f64, scale_factor: f64, writer: anytype) !void {
7172
try writer.writeAll("(footprint \"DrillHole\"\n");
7273
try writer.writeAll("(layer \"F.Cu\")\n");
73-
try writer.print(" (at {d:.3} {d:.3})\n", .{x * scale_factor, y * scale_factor});
74+
try writer.print(" (at {d:.3} {d:.3})\n", .{ x * scale_factor, y * scale_factor });
7475
try writer.writeAll(" (attr board_only exclude_from_pos_files exclude_from_bom)\n");
75-
try writer.writeAll(" (tstamp \"e9dc178a-3c62-11ed-ab80-7a0c86e760e0\")\n");
76-
try writer.writeAll(" (tedit \"e9dc1794-3c62-11ed-ab80-7a0c86e760e0\")\n");
76+
try writer.print(" (tstamp \"{s}\")\n", .{FauxUUID.init()});
77+
try writer.print(" (tedit \"{s}\")\n", .{FauxUUID.init()});
7778
try writer.print("(pad \"\" np_thru_hole circle (at 0 0) (size {d:.3} {d:.3}) (drill {d:.3}) (layers *.Cu *.Mask)", .{
7879
d * scale_factor,
7980
d * scale_factor,
8081
d * scale_factor,
8182
});
82-
try writer.writeAll("(clearance 0.1) (zone_connect 0) (tstamp 1c533c1a-46c3-11ed-bce4-7a0c86e760e0))");
83+
try writer.print("(clearance 0.1) (zone_connect 0) (tstamp {s}))", .{FauxUUID.init()});
8384

8485
try writer.writeAll(")\n");
8586
}

0 commit comments

Comments
 (0)