1 #pragma once
2 #include <string>
3 #include <list>
4 #include <vector>
5 #include "common/common.hpp"
6 #include "pool/unit.hpp"
7 #include "pool/symbol.hpp"
8 #include "pool/entity.hpp"
9 #include "pool/part.hpp"
10 
11 namespace horizon {
12 
13 
14 class KiCadSymbol {
15 public:
16     std::string name;
17     std::string prefix;
18     std::string footprint;
19     std::string datasheet;
20     std::string description;
21     std::vector<std::string> fplist;
22     class SPart {
23     public:
24         class SRect {
25         public:
26             Coordi from;
27             Coordi to;
28         };
29         std::list<SRect> rects;
30         class SPoly {
31         public:
32             std::vector<Coordi> vertices;
33             bool is_closed = false;
34         };
35         std::list<SPoly> polys;
36 
37         class SPin {
38         public:
39             std::string name;
40             std::string pad;
41             Coordi pos;
42             int64_t length;
43             Orientation orientation;
44             Pin::Direction direction;
45             SymbolPin::Decoration decoration;
46         };
47         std::list<SPin> pins;
48     };
49     std::vector<SPart> parts;
50     unsigned int get_n_pins() const;
51 
52     class SPartIterProxy {
53     public:
SPartIterProxy(std::vector<SPart> & p,int i)54         SPartIterProxy(std::vector<SPart> &p, int i) : parts(p), idx(i)
55         {
56         }
begin()57         auto begin()
58         {
59             if (idx == 0) {
60                 return parts.begin();
61             }
62             else if (idx > parts.size()) {
63                 return parts.begin();
64             }
65             else {
66                 return parts.begin() + (idx - 1);
67             }
68         }
69 
end()70         auto end()
71         {
72             if (idx == 0) {
73                 return parts.end();
74             }
75             else if (idx > parts.size()) {
76                 return parts.begin();
77             }
78             else {
79                 return begin() + 1;
80             }
81         }
82 
83     private:
84         std::vector<SPart> &parts;
85         const size_t idx;
86     };
87 
88     SPartIterProxy get_parts(int idx);
89 };
90 
91 std::list<KiCadSymbol> parse_kicad_library(const std::string &filename);
92 class KiCadSymbolImporter {
93 public:
94     KiCadSymbolImporter(const KiCadSymbol &sym, const class Package *pkg, bool merge_pins);
95 
96     const Entity &get_entity();
97     const Part *get_part();
98     const std::list<Unit> &get_units();
99     const std::list<Symbol> &get_symbols();
100 
101 private:
102     Entity entity;
103     Part part;
104     std::list<Unit> units;
105     std::list<Symbol> symbols;
106     // const KiCadSymbol &symbol;
107     // const class Package *package;
108 };
109 
110 } // namespace horizon
111