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