diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-07-26 00:22:55 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-07-26 00:22:55 +0200 |
commit | 128e53d220d97225803d61d86f8e43439563181d (patch) | |
tree | e0d5da8d666c54d1d17e64ee6f52af424129f90d /include | |
download | kicad-utils-128e53d220d97225803d61d86f8e43439563181d.tar.gz kicad-utils-128e53d220d97225803d61d86f8e43439563181d.tar.bz2 kicad-utils-128e53d220d97225803d61d86f8e43439563181d.tar.xz kicad-utils-128e53d220d97225803d61d86f8e43439563181d.zip |
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.
Diffstat (limited to 'include')
-rw-r--r-- | include/trygvis/kicad.h | 80 |
1 files changed, 80 insertions, 0 deletions
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 <string> +#include <vector> +#include <stdexcept> +#include <experimental/optional> + +namespace trygvis { +namespace kicad { + +template<typename T> +using opt = std::experimental::optional<T>; + +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<pin> 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<node> nodes; + + net(int code, const std::string &name, const std::vector<node> &nodes) : code(code), name(name), nodes(nodes) { } +}; + +struct netlist { + std::vector<component> components; + std::vector<part> parts; + std::vector<net> nets; + + opt<const component *> find_component(std::string ref) const; +}; + +class kicad_parse_exception : public std::runtime_error { +public: + explicit kicad_parse_exception(const std::vector<std::string> &messages) : + runtime_error("Parse error"), messages(messages) { } + + const std::vector<std::string> 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 |