Horizon
canvas.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "common/text.hpp"
4 #include "layer_display.hpp"
5 #include "selectables.hpp"
6 #include "target.hpp"
7 #include "triangle.hpp"
8 #include "object_ref.hpp"
9 #include "fragment_cache.hpp"
10 #include "util/placement.hpp"
11 #include "util/text_data.hpp"
12 #include "color_palette.hpp"
13 #include <array>
14 #include <set>
15 #include <unordered_map>
16 #include <deque>
17 #include <list>
18 #include "picture.hpp"
19 #include "util/vector_pair.hpp"
20 
21 namespace horizon {
22 class Canvas {
23  friend Selectables;
24  friend class SelectionFilter;
25  friend class CanvasAnnotation;
26 
27 public:
28  Canvas();
29  virtual ~Canvas()
30  {
31  }
32  virtual void clear();
33  void update(const class Symbol &sym, const Placement &transform = Placement(), bool edit = true);
34  void update(const class Sheet &sheet);
35  void update(const class Padstack &padstack, bool edit = true);
36  void update(const class Package &pkg, bool edit = true);
37  void update(const class Buffer &buf, class LayerProvider *lp);
38  enum class PanelMode { INCLUDE, SKIP };
39  void update(const class Board &brd, PanelMode mode = PanelMode::INCLUDE);
40  void update(const class Frame &fr, bool edit = true);
41  void update(const class Decal &dec, bool edit = true);
42 
43  ObjectRef add_line(const std::deque<Coordi> &pts, int64_t width, ColorP color, int layer);
44  void remove_obj(const ObjectRef &r);
45  void hide_obj(const ObjectRef &r);
46  void show_obj(const ObjectRef &r);
47  void set_flags(const ObjectRef &r, uint8_t mask_set, uint8_t mask_clear);
48  void set_flags_all(uint8_t mask_set, uint8_t mask_clear);
49 
50  void reset_color2();
51  void set_color2(const ObjectRef &r, uint8_t color);
52 
53  void show_all_obj();
54 
55  virtual void update_markers()
56  {
57  }
58 
59  const LayerDisplay &get_layer_display(int index) const;
60  void set_layer_display(int index, const LayerDisplay &ld);
61  void set_layer_color(int layer, const Color &color);
62 
63  bool layer_is_visible(int layer) const;
64  bool layer_is_visible(LayerRange layer) const;
65 
66  bool show_all_junctions_in_schematic = false;
67  bool show_text_in_tracks = false;
68  bool show_text_in_vias = false;
69 
70  virtual bool get_flip_view() const
71  {
72  return false;
73  };
74 
75  std::pair<Coordf, Coordf> get_bbox(bool visible_only = true) const;
76 
77  static const int first_overlay_layer = 30000;
78 
79 protected:
80  std::map<int, vector_pair<Triangle, TriangleInfo>> triangles;
81  std::list<CanvasPicture> pictures;
82  void add_triangle(int layer, const Coordf &p0, const Coordf &p1, const Coordf &p2, ColorP co, uint8_t flg = 0,
83  uint8_t color2 = 0);
84 
85  using ObjectRefIdx = std::map<int, std::pair<size_t, size_t>>;
86  std::unordered_map<ObjectRef, ObjectRefIdx> object_refs;
87  void begin_group(int layer);
88  void end_group();
89  std::vector<ObjectRef> object_refs_current;
90  std::vector<ObjectRefIdx *> object_ref_idx;
91  void object_ref_push(const ObjectRef &ref);
92  template <typename... Args> void object_ref_push(Args... args)
93  {
94  object_ref_push(ObjectRef(args...));
95  }
96  void object_ref_pop();
97 
98  void render(const class Symbol &sym, bool on_sheet = false, bool smashed = false, ColorP co = ColorP::FROM_LAYER);
99  void render(const class Junction &junc, bool interactive = true, ObjectType mode = ObjectType::INVALID);
100  void render(const class Line &line, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
101  void render(const class SymbolPin &pin, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
102  void render(const class Arc &arc, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
103  void render(const class Sheet &sheet);
104  void render(const class SchematicSymbol &sym);
105  void render(const class LineNet &line);
106  void render(const class NetLabel &label);
107  void render(const class BusLabel &label);
108  void render(const class Warning &warn);
109  void render(const class PowerSymbol &sym);
110  void render(const class BusRipper &ripper);
111  void render(const class Text &text, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
112  void render(const class Padstack &padstack, bool interactive = true);
113  void render(const class Polygon &polygon, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
114  void render(const class Shape &shape, bool interactive = true);
115  void render(const class Hole &hole, bool interactive = true);
116  void render(const class Package &package, bool interactive = true, bool smashed = false,
117  bool omit_silkscreen = false, bool omit_outline = false);
118  void render_pad_overlay(const class Pad &pad);
119  void render(const class Pad &pad);
120  void render(const class Buffer &buf);
121  enum class OutlineMode { INCLUDE, OMIT };
122  void render(const class Board &brd, bool interactive = true, PanelMode mode = PanelMode::INCLUDE,
123  OutlineMode outline_mode = OutlineMode::INCLUDE);
124  void render(const class BoardPackage &pkg, bool interactive = true);
125  void render(const class BoardHole &hole, bool interactive = true);
126  void render(const class Track &track, bool interactive = true);
127  void render(const class Via &via, bool interactive = true);
128  void render(const class Dimension &dim);
129  void render(const class Frame &frame, bool on_sheet = false);
130  void render(const class ConnectionLine &line);
131  void render(const class BoardPanel &panel);
132  void render(const class Picture &pic);
133  void render(const class Decal &decal, bool interactive = true);
134  void render(const class BoardDecal &decal);
135 
136  bool needs_push = true;
137  virtual void request_push() = 0;
138  virtual void push() = 0;
139 
140  void set_lod_size(float size);
141 
142  void draw_line(const Coord<float> &a, const Coord<float> &b, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
143  bool tr = true, uint64_t width = 0);
144  void draw_cross(const Coord<float> &o, float size, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
145  bool tr = true, uint64_t width = 0);
146  void draw_plus(const Coord<float> &o, float size, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
147  bool tr = true, uint64_t width = 0);
148  void draw_box(const Coord<float> &o, float size, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
149  bool tr = true, uint64_t width = 0);
150  void draw_arc(const Coord<float> &center, float radius, float a0, float a1, ColorP color = ColorP::FROM_LAYER,
151  int layer = 10000, bool tr = true, uint64_t width = 0);
152  std::pair<Coordf, Coordf> draw_arc2(const Coord<float> &center, float radius0, float a0, float radius1, float a1,
153  ColorP color = ColorP::FROM_LAYER, int layer = 10000, bool tr = true,
154  uint64_t width = 0);
155  std::pair<Coordf, Coordf> draw_text0(const Coordf &p, float size, const std::string &rtext, int angle, bool flip,
156  TextOrigin origin, ColorP color, int layer = 10000, uint64_t width = 0,
157  bool draw = true, TextData::Font font = TextData::Font::SIMPLEX,
158  bool center = false, bool mirror = false);
159 
160  virtual void draw_bitmap_text(const Coordf &p, float scale, const std::string &rtext, int angle, ColorP color,
161  int layer)
162  {
163  }
164 
165  virtual std::pair<Coordf, Coordf> measure_bitmap_text(const std::string &text) const
166  {
167  return {{0, 0}, {0, 0}};
168  }
169 
170  enum class TextBoxMode { FULL, LOWER, UPPER };
171 
172  virtual void draw_bitmap_text_box(const Placement &q, float width, float height, const std::string &s, ColorP color,
173  int layer, TextBoxMode mode)
174  {
175  }
176 
177  void draw_error(const Coordf &center, float scale, const std::string &text, bool tr = true);
178  std::tuple<Coordf, Coordf, Coordi> draw_flag(const Coordf &position, const std::string &txt, int64_t size,
179  Orientation orientation, ColorP color = ColorP::FROM_LAYER);
180  void draw_lock(const Coordf &center, float size, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
181  bool tr = true);
182 
183  virtual void img_net(const class Net *net)
184  {
185  }
186  virtual void img_polygon(const Polygon &poly, bool tr = true)
187  {
188  }
189  virtual void img_padstack(const Padstack &ps)
190  {
191  }
192  virtual void img_set_padstack(bool v)
193  {
194  }
195  virtual void img_line(const Coordi &p0, const Coordi &p1, const uint64_t width, int layer = 10000, bool tr = true);
196  virtual void img_hole(const Hole &hole)
197  {
198  }
199  virtual void img_patch_type(PatchType type)
200  {
201  }
202  virtual void img_text(const Text &txt, std::pair<Coordf, Coordf> &extents)
203  {
204  }
205  virtual void img_draw_text(const Coordf &p, float size, const std::string &rtext, int angle, bool flip,
206  TextOrigin origin, int layer = 10000, uint64_t width = 0,
207  TextData::Font font = TextData::Font::SIMPLEX, bool center = false, bool mirror = false)
208  {
209  }
210  bool img_mode = false;
211  bool img_auto_line = false;
212 
213  Placement transform;
214  void transform_save();
215  void transform_restore();
216  std::list<Placement> transforms;
217 
218  Selectables selectables;
219  std::vector<Target> targets;
220  Target target_current;
221 
222  const class LayerProvider *layer_provider = nullptr;
223  std::map<int, Color> layer_colors;
224  Color get_layer_color(int layer) const;
225  int work_layer = 0;
226  std::map<int, LayerDisplay> layer_display;
227 
228  UUID sheet_current_uuid;
229 
230  TriangleInfo::Type triangle_type_current = TriangleInfo::Type::NONE;
231 
232  std::map<std::pair<int, bool>, int> overlay_layers; // layer, ignore_flip -> overlay layer
233  int overlay_layer_current = first_overlay_layer;
234  int get_overlay_layer(int layer, bool ignore_flip = false);
235  bool is_overlay_layer(int overlay_layer, int layer) const;
236 
237  FragmentCache fragment_cache;
238 
239 private:
240  uint8_t lod_current = 0;
241 
242  int group_layer = 0;
243  vector_pair<Triangle, TriangleInfo> *group_tris = nullptr;
244  size_t group_size = 0;
245 };
246 } // namespace horizon
libzip::uint8_t
zip_uint8_t uint8_t
zip_uint8_t typedef.
Definition: zip.hpp:78
libzip::int64_t
zip_int64_t int64_t
zip_int64_t typedef.
Definition: zip.hpp:103
libzip::uint64_t
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108