From 128e53d220d97225803d61d86f8e43439563181d Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 26 Jul 2016 00:22:55 +0200 Subject: WIP: kicad_gen is a util to generate schematic.h files from KiCAD netlist files. Current code contains a lexer and parser for KiCAD's netlist files and code to build a tree of the netlist which can be used for generation. Contains CMake code for integrating the generation into CMake too. --- include/trygvis/kicad.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 include/trygvis/kicad.h (limited to 'include') diff --git a/include/trygvis/kicad.h b/include/trygvis/kicad.h new file mode 100644 index 0000000..4cff944 --- /dev/null +++ b/include/trygvis/kicad.h @@ -0,0 +1,80 @@ +#pragma once + +#include +#include +#include +#include + +namespace trygvis { +namespace kicad { + +template +using opt = std::experimental::optional; + +class component { +public: + std::string ref; + std::string value; + + component(const std::string &ref, const std::string &value) : ref(ref), value(value) { } +}; + +struct pin { + int num; + std::string name; + std::string type; +}; + +struct part { + std::vector pins; +}; + +class node { +public: + std::string ref; + int pin; + + node(const std::string &ref, int pin) : ref(ref), pin(pin) { } +}; + +class net { +public: + int code; + std::string name; + std::vector nodes; + + net(int code, const std::string &name, const std::vector &nodes) : code(code), name(name), nodes(nodes) { } +}; + +struct netlist { + std::vector components; + std::vector parts; + std::vector nets; + + opt find_component(std::string ref) const; +}; + +class kicad_parse_exception : public std::runtime_error { +public: + explicit kicad_parse_exception(const std::vector &messages) : + runtime_error("Parse error"), messages(messages) { } + + const std::vector messages; +}; + +class kicad_net_loader { +public: + kicad_net_loader(); + + virtual ~kicad_net_loader(); + + netlist load(std::string path); + + void setDebug(bool debug); + +private: + bool debug_; +}; + +} // namespace kicad +} // namespace trygvis -- cgit v1.2.3