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