Horizon
Loading...
Searching...
No Matches
features.hpp
1#pragma once
2#include "attribute_util.hpp"
3#include "common/common.hpp"
4#include "util/placement.hpp"
5#include "surface_data.hpp"
6#include <list>
7
8namespace horizon {
9class Shape;
10}
11
12namespace horizon::ODB {
13
15public:
17 public:
18 template <typename T> using check_type = attribute::is_feature<T>;
19
20 friend Features;
21 virtual void write(std::ostream &ost) const;
22
23 const unsigned int index;
24
25 virtual ~Feature() = default;
26
27 protected:
28 Feature(unsigned int i) : index(i)
29 {
30 }
31
32 enum class Type { LINE, ARC, PAD, SURFACE };
33 virtual Type get_type() const = 0;
34 virtual void write_feature(std::ostream &ost) const = 0;
35 };
36
37 class Line : public Feature {
38 public:
39 Type get_type() const override
40 {
41 return Type::LINE;
42 }
43
44 Line(unsigned int i, const Coordi &f, const Coordi &t, unsigned int sym)
45 : Feature(i), from(f), to(t), symbol(sym)
46 {
47 }
48 Coordi from;
49 Coordi to;
50 unsigned int symbol;
51
52 protected:
53 void write_feature(std::ostream &ost) const override;
54 };
55
56
57 class Arc : public Feature {
58 public:
59 Type get_type() const override
60 {
61 return Type::ARC;
62 }
63
64 enum class Direction { CW, CCW };
65
66 Arc(unsigned int i, const Coordi &f, const Coordi &t, const Coordi &c, unsigned int sym, Direction d)
67 : Feature(i), from(f), to(t), center(c), symbol(sym), direction(d)
68 {
69 }
70 Coordi from;
71 Coordi to;
72 Coordi center;
73
74 unsigned int symbol;
75 Direction direction;
76
77 protected:
78 void write_feature(std::ostream &ost) const override;
79 };
80
81 class Pad : public Feature {
82 public:
83 Type get_type() const override
84 {
85 return Type::PAD;
86 }
87
88 Pad(unsigned int i, const Placement &pl, unsigned int sym) : Feature(i), placement(pl), symbol(sym)
89 {
90 }
91
92 Placement placement;
93 unsigned int symbol;
94
95 protected:
96 void write_feature(std::ostream &ost) const override;
97 };
98
99 class Surface : public Feature {
100 public:
101 Surface(unsigned int i) : Feature(i)
102 {
103 }
104
105 void write(std::ostream &ost) const override;
106 Type get_type() const override
107 {
108 return Type::SURFACE;
109 }
110
111 SurfaceData data;
112
113 protected:
114 void write_feature(std::ostream &ost) const override;
115 };
116
117 Line &draw_line(const Coordi &from, const Coordi &to, uint64_t width);
118 Arc &draw_arc(const Coordi &from, const Coordi &to, const Coordi &center, uint64_t width, Arc::Direction direction);
119
120 std::vector<Feature *> draw_polygon_outline(const Polygon &poly, const Placement &transform);
121
122 Pad &draw_pad(const std::string &sym, const Placement &transform);
123 Pad &draw_circle(const Coordi &pos, uint64_t diameter);
124 Pad &draw_shape(const Shape &shape);
125 Surface &add_surface();
126
127 void write(std::ostream &ost) const;
128
129private:
130 unsigned int get_or_create_symbol_circle(uint64_t diameter);
131 unsigned int get_or_create_symbol_pad(const std::string &name);
132 unsigned int get_or_create_symbol_rect(uint64_t width, uint64_t height);
133 unsigned int get_or_create_symbol_oval(uint64_t width, uint64_t height);
134
135 unsigned int symbol_n = 0;
136
137 template <typename T> unsigned int get_or_create_symbol(std::map<T, unsigned int> &syms, const T &key)
138 {
139 if (syms.count(key)) {
140 return syms.at(key);
141 }
142 else {
143 auto n = symbol_n++;
144 syms.emplace(key, n);
145 return n;
146 }
147 }
148
149 std::map<uint64_t, unsigned int> symbols_circle; // diameter -> symbol index
150 std::map<std::string, unsigned int> symbols_pad; // name -> symbol index
151 std::map<std::pair<uint64_t, uint64_t>, unsigned int> symbols_rect; // w,h -> symbol index
152 std::map<std::pair<uint64_t, uint64_t>, unsigned int> symbols_oval; // w,h -> symbol index
153
154 template <typename T, typename... Args> T &add_feature(Args &&...args)
155 {
156 auto f = std::make_unique<T>(features.size(), std::forward<Args>(args)...);
157 auto &r = *f;
158 features.push_back(std::move(f));
159 return r;
160 }
161 std::list<std::unique_ptr<Feature>> features;
162};
163
164} // namespace horizon::ODB
Definition attribute_util.hpp:10
Definition features.hpp:57
Definition features.hpp:16
Definition features.hpp:37
Definition features.hpp:81
Definition features.hpp:99
Definition features.hpp:14
Definition attribute_util.hpp:56
Definition surface_data.hpp:17
Definition placement.hpp:8
Polygon used in Padstack, Package and Board for specifying filled Regions.
Definition polygon.hpp:25
For commonly used Pad shapes.
Definition shape.hpp:15
Definition attributes.hpp:50