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  enum class PanelMode { INCLUDE, SKIP };
38  void update(const class Board &brd, PanelMode mode = PanelMode::INCLUDE);
39  void update(const class Frame &fr, bool edit = true);
40  void update(const class Decal &dec, bool edit = true);
41 
42  ObjectRef add_line(const std::deque<Coordi> &pts, int64_t width, ColorP color, int layer);
43  void remove_obj(const ObjectRef &r);
44  void hide_obj(const ObjectRef &r);
45  void show_obj(const ObjectRef &r);
46  void set_flags(const ObjectRef &r, uint8_t mask_set, uint8_t mask_clear);
47  void set_flags_all(uint8_t mask_set, uint8_t mask_clear);
48 
49  void reset_color2();
50  void set_color2(const ObjectRef &r, uint8_t color);
51 
52  void show_all_obj();
53 
54  virtual void update_markers()
55  {
56  }
57 
58  const LayerDisplay &get_layer_display(int index) const;
59  void set_layer_display(int index, const LayerDisplay &ld);
60  void set_layer_color(int layer, const Color &color);
61 
62  bool layer_is_visible(int layer) const;
63  bool layer_is_visible(LayerRange layer) const;
64 
65  bool show_all_junctions_in_schematic = false;
66  bool show_text_in_tracks = false;
67  bool show_text_in_vias = false;
68 
69  virtual bool get_flip_view() const
70  {
71  return false;
72  };
73 
74  virtual float get_view_angle() const
75  {
76  return 0;
77  }
78 
79  std::pair<Coordf, Coordf> get_bbox(bool visible_only = true) const;
80 
81  static const int first_overlay_layer = 30000;
82 
83 protected:
84  std::map<int, vector_pair<Triangle, TriangleInfo>> triangles;
85  std::list<CanvasPicture> pictures;
86  void add_triangle(int layer, const Coordf &p0, const Coordf &p1, const Coordf &p2, ColorP co, uint8_t flg = 0,
87  uint8_t color2 = 0);
88 
89  using ObjectRefIdx = std::map<int, std::pair<size_t, size_t>>;
90  std::unordered_map<ObjectRef, ObjectRefIdx> object_refs;
91  void begin_group(int layer);
92  void end_group();
93  std::vector<ObjectRef> object_refs_current;
94  std::vector<ObjectRefIdx *> object_ref_idx;
95  void object_ref_push(const ObjectRef &ref);
96  template <typename... Args> void object_ref_push(Args... args)
97  {
98  object_ref_push(ObjectRef(args...));
99  }
100  void object_ref_pop();
101 
102  void render(const class Symbol &sym, bool on_sheet = false, bool smashed = false, ColorP co = ColorP::FROM_LAYER);
103  void render(const class Junction &junc, bool interactive = true, ObjectType mode = ObjectType::INVALID);
104  void render(const class SchematicJunction &junc);
105  void render(const class Line &line, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
106  void render(const class SymbolPin &pin, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
107  void render(const class Arc &arc, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
108  void render(const class Sheet &sheet);
109  void render(const class SchematicSymbol &sym);
110  void render(const class LineNet &line);
111  void render(const class NetLabel &label);
112  void render(const class BusLabel &label);
113  void render(const class Warning &warn);
114  void render(const class PowerSymbol &sym);
115  void render(const class BusRipper &ripper);
116  void render(const class Text &text, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
117  void render(const class Padstack &padstack, bool interactive = true);
118  void render(const class Polygon &polygon, bool interactive = true, ColorP co = ColorP::FROM_LAYER);
119  void render(const class Shape &shape, bool interactive = true);
120  void render(const class Hole &hole, bool interactive = true);
121  void render(const class Package &package, bool interactive = true, bool smashed = false,
122  bool omit_silkscreen = false, bool omit_outline = false);
123  void render_pad_overlay(const class Pad &pad);
124  void render(const class Pad &pad);
125  enum class OutlineMode { INCLUDE, OMIT };
126  void render(const class Board &brd, bool interactive = true, PanelMode mode = PanelMode::INCLUDE,
127  OutlineMode outline_mode = OutlineMode::INCLUDE);
128  void render(const class BoardPackage &pkg, bool interactive = true);
129  void render(const class BoardHole &hole, bool interactive = true);
130  void render(const class Track &track, bool interactive = true);
131  void render(const class Via &via, bool interactive = true);
132  void render(const class Dimension &dim);
133  void render(const class Frame &frame, bool on_sheet = false);
134  void render(const class ConnectionLine &line);
135  void render(const class BoardPanel &panel);
136  void render(const class Picture &pic);
137  void render(const class Decal &decal, bool interactive = true);
138  void render(const class BoardDecal &decal);
139 
140  bool needs_push = true;
141  virtual void request_push() = 0;
142  virtual void push() = 0;
143 
144  void set_lod_size(float size);
145 
146  void draw_line(const Coord<float> &a, const Coord<float> &b, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
147  bool tr = true, uint64_t width = 0);
148  void draw_cross(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_plus(const Coord<float> &o, float size, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
151  bool tr = true, uint64_t width = 0);
152  void draw_box(const Coord<float> &o, float size, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
153  bool tr = true, uint64_t width = 0);
154  void draw_arc(const Coord<float> &center, float radius, float a0, float a1, ColorP color = ColorP::FROM_LAYER,
155  int layer = 10000);
156  void draw_circle(const Coord<float> &center, float radius, ColorP color = ColorP::FROM_LAYER, int layer = 10000);
157  std::pair<Coordf, Coordf> draw_arc2(const Coord<float> &center, float radius0, float a0, float a1, ColorP color,
158  int layer, uint64_t width);
159  void draw_arc0(const Coord<float> &center, float radius0, float a0, float a1, ColorP color, int layer,
160  uint64_t width);
161  std::pair<Coordf, Coordf> draw_text0(const Coordf &p, float size, const std::string &rtext, int angle, bool flip,
162  TextOrigin origin, ColorP color, int layer = 10000, uint64_t width = 0,
163  bool draw = true, TextData::Font font = TextData::Font::SIMPLEX,
164  bool center = false, bool mirror = false);
165 
166  virtual void draw_bitmap_text(const Coordf &p, float scale, const std::string &rtext, int angle, ColorP color,
167  int layer)
168  {
169  }
170 
171  virtual std::pair<Coordf, Coordf> measure_bitmap_text(const std::string &text) const
172  {
173  return {{0, 0}, {0, 0}};
174  }
175 
176  enum class TextBoxMode { FULL, LOWER, UPPER };
177 
178  virtual void draw_bitmap_text_box(const Placement &q, float width, float height, const std::string &s, ColorP color,
179  int layer, TextBoxMode mode)
180  {
181  }
182 
183  void draw_error(const Coordf &center, float scale, const std::string &text, bool tr = true);
184  std::tuple<Coordf, Coordf, Coordi> draw_flag(const Coordf &position, const std::string &txt, int64_t size,
185  Orientation orientation, ColorP color = ColorP::FROM_LAYER);
186  void draw_lock(const Coordf &center, float size, ColorP color = ColorP::FROM_LAYER, int layer = 10000,
187  bool tr = true);
188 
189  virtual bool img_layer_is_visible(int layer) const
190  {
191  return true;
192  }
193  virtual void img_net(const class Net *net)
194  {
195  }
196  virtual void img_polygon(const Polygon &poly, bool tr = true)
197  {
198  }
199  virtual void img_padstack(const Padstack &ps)
200  {
201  }
202  virtual void img_set_padstack(bool v)
203  {
204  }
205  virtual void img_line(const Coordi &p0, const Coordi &p1, const uint64_t width, int layer = 10000, bool tr = true);
206  virtual void img_hole(const Hole &hole)
207  {
208  }
209  virtual void img_patch_type(PatchType type)
210  {
211  }
212  virtual void img_draw_text(const Coordf &p, float size, const std::string &rtext, int angle, bool flip,
213  TextOrigin origin, int layer = 10000, uint64_t width = 0,
214  TextData::Font font = TextData::Font::SIMPLEX, bool center = false, bool mirror = false)
215  {
216  }
217  bool img_mode = false;
218  bool img_auto_line = false;
219 
220  Placement transform;
221  void transform_save();
222  void transform_restore();
223  std::list<Placement> transforms;
224 
225  Selectables selectables;
226  std::vector<Target> targets;
227  Target target_current;
228 
229  const class LayerProvider *layer_provider = nullptr;
230  std::map<int, Color> layer_colors;
231  Color get_layer_color(int layer) const;
232  int work_layer = 0;
233  std::map<int, LayerDisplay> layer_display;
234 
235  UUID sheet_current_uuid;
236 
237  TriangleInfo::Type triangle_type_current = TriangleInfo::Type::NONE;
238 
239  std::map<std::pair<LayerRange, bool>, int> overlay_layers; // layer, ignore_flip -> overlay layer
240  int overlay_layer_current = first_overlay_layer;
241  int get_overlay_layer(const LayerRange &layer, bool ignore_flip = false);
242  bool is_overlay_layer(int overlay_layer, int layer) const;
243 
244  FragmentCache fragment_cache;
245 
246 private:
247  uint8_t lod_current = 0;
248 
249  int group_layer = 0;
250  vector_pair<Triangle, TriangleInfo> *group_tris = nullptr;
251  size_t group_size = 0;
252 };
253 } // namespace horizon
Graphical arc.
Definition: arc.hpp:20
Definition: board_decal.hpp:11
Definition: board_hole.hpp:12
Definition: board_package.hpp:15
Definition: board_panel.hpp:7
Definition: board.hpp:42
Makes a Bus available on the schematic.
Definition: bus_label.hpp:16
Make a Bus member's Net available on the schematic.
Definition: bus_ripper.hpp:19
Definition: annotation.hpp:7
Definition: canvas.hpp:22
Definition: common.hpp:234
Definition: connection_line.hpp:15
Definition: decal.hpp:16
Definition: dimension.hpp:12
Definition: fragment_cache.hpp:7
Definition: frame.hpp:21
A hole with diameter and position, that's it.
Definition: hole.hpp:18
A Junction is a point in 2D-Space.
Definition: junction.hpp:20
Definition: layer_display.hpp:5
Definition: layer_provider.hpp:7
Definition: layer_range.hpp:7
LineNet is similar to Line, except it denotes electrical connection.
Definition: line_net.hpp:17
Graphical line.
Definition: line.hpp:19
Displays the junction's Net name it is attached to.
Definition: net_label.hpp:20
Definition: net.hpp:15
Definition: object_ref.hpp:7
Definition: package.hpp:29
Definition: pad.hpp:15
Definition: padstack.hpp:21
Definition: picture.hpp:10
Definition: placement.hpp:8
Polygon used in Padstack, Package and Board for specifying filled Regions.
Definition: polygon.hpp:27
GND symbols and the like.
Definition: power_symbol.hpp:16
Definition: schematic_junction.hpp:6
Definition: schematic_symbol.hpp:17
Definition: selectables.hpp:65
Definition: selection_filter.hpp:6
For commonly used Pad shapes.
Definition: shape.hpp:18
Definition: sheet.hpp:39
Definition: symbol.hpp:19
Definition: symbol.hpp:71
Definition: target.hpp:7
Used wherever a user-editable text is needed.
Definition: text.hpp:18
Definition: track.hpp:16
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: via.hpp:16
Definition: warning.hpp:6
Definition: vector_pair.hpp:8
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108
zip_int64_t int64_t
zip_int64_t typedef.
Definition: zip.hpp:103
zip_uint8_t uint8_t
zip_uint8_t typedef.
Definition: zip.hpp:78