Horizon
schematic.hpp
1 #pragma once
2 #include "util/uuid.hpp"
3 #include "nlohmann/json_fwd.hpp"
4 #include "pool/unit.hpp"
5 #include "block/block.hpp"
6 #include "sheet.hpp"
7 #include "schematic_rules.hpp"
8 #include "common/pdf_export_settings.hpp"
9 #include <glibmm/regex.h>
10 #include <vector>
11 #include <map>
12 #include "util/file_version.hpp"
13 #include "util/template_util.hpp"
14 
15 namespace horizon {
16 using json = nlohmann::json;
17 
29 class Schematic {
30 private:
31  unsigned int update_nets();
32 
33 public:
34  Schematic(const UUID &uu, const json &, Block &block, class IPool &pool,
36  static Schematic new_from_file(const std::string &filename, Block &block, IPool &pool,
38  Schematic(const UUID &uu, Block &block);
39  static unsigned int get_app_version();
40 
46  void expand(bool careful = false, const class IInstanceMappingProvider *inst_map = nullptr);
47  void expand_connectivity(bool carful = false);
48 
49  Schematic(const Schematic &sch);
50  void operator=(const Schematic &sch) = delete;
59  void update_refs();
60 
65  void disconnect_symbol(Sheet *sheet, SchematicSymbol *sym);
66 
71  void autoconnect_symbol(Sheet *sheet, SchematicSymbol *sym);
72  void autoconnect_block_symbol(Sheet *sheet, SchematicBlockSymbol *sym);
73 
77  void smash_symbol(Sheet *sheet, SchematicSymbol *sym);
78 
82  void unsmash_symbol(Sheet *sheet, SchematicSymbol *sym);
83 
84  bool delete_net_line(Sheet *sheet, LineNet *line);
85 
86  bool place_bipole_on_line(Sheet *sheet, SchematicSymbol *sym);
87 
88  void swap_gates(const UUID &comp, const UUID &g1, const UUID &g2);
89 
90  void disconnect_block_symbol(Sheet *sheet, SchematicBlockSymbol *sym);
91 
92  std::map<UUIDPath<2>, std::string> get_unplaced_gates() const;
93 
94  Sheet &add_sheet();
95  void delete_sheet(const UUID &uu);
96  Sheet &get_sheet_at_index(unsigned int index);
97  const Sheet &get_sheet_at_index(unsigned int index) const;
98 
99  static Glib::RefPtr<Glib::Regex> get_sheetref_regex();
100 
101  UUID uuid;
102  Block *block;
103  std::string name;
104  std::map<UUID, Sheet> sheets;
105  SchematicRules rules;
106  bool group_tag_visible = false;
107 
108 
109  class Annotation {
110  public:
111  Annotation(const json &j);
112  Annotation();
113  enum class Order { RIGHT_DOWN, DOWN_RIGHT };
114  Order order = Order::RIGHT_DOWN;
115 
116  enum class Mode { SEQUENTIAL, SHEET_100, SHEET_1000 };
117  Mode mode = Mode::SHEET_100;
118 
119  bool fill_gaps = true;
120  bool keep = true;
121  bool ignore_unknown = false;
122  json serialize() const;
123  };
124 
125  Annotation annotation;
126  void annotate();
127 
128  class SheetMapping {
129  public:
130  std::map<UUIDVec, unsigned int> sheet_numbers;
131  unsigned int sheet_total;
132  void update(const Schematic &sch);
133 
134  private:
135  void update(const Schematic &sch, const UUIDVec &instance_path);
136  unsigned int index;
137  };
138  SheetMapping sheet_mapping;
139 
140  void update_sheet_mapping();
141 
142  template <bool c> struct SheetItem {
143  SheetItem(make_const_ref_t<c, Sheet> sh, unsigned int i, make_const_ref_t<c, Schematic> sch, const UUIDVec &p)
144  : sheet(sh), sheet_index(i), schematic(sch), instance_path(p)
145  {
146  }
147  make_const_ref_t<c, Sheet> sheet;
148  unsigned int sheet_index;
149  make_const_ref_t<c, Schematic> schematic;
150  UUIDVec instance_path;
151  };
152 
153  std::vector<SheetItem<false>> get_all_sheets();
154  std::vector<SheetItem<true>> get_all_sheets() const;
155 
156  PDFExportSettings pdf_export_settings;
157 
158  FileVersion version;
159 
160  json serialize() const;
161  void load_pictures(const std::string &dir);
162 
163  ItemSet get_pool_items_used() const;
164 
165  std::vector<Sheet *> get_sheets_sorted();
166  std::vector<const Sheet *> get_sheets_sorted() const;
167 
168 private:
169  void expand_frames(const IInstanceMappingProvider *inst_map);
170 };
171 } // namespace horizon
A block is one level of hierarchy in the netlist.
Definition: block.hpp:29
Definition: file_version.hpp:9
Definition: iblock_symbol_and_schematic_provider.hpp:6
Definition: iinstancce_mapping_provider.hpp:4
Definition: ipool.hpp:14
LineNet is similar to Line, except it denotes electrical connection.
Definition: line_net.hpp:17
Definition: pdf_export_settings.hpp:9
Definition: schematic_block_symbol.hpp:12
Definition: schematic_rules.hpp:10
Definition: schematic_symbol.hpp:15
Definition: schematic.hpp:109
Definition: schematic.hpp:128
A Schematic is the visual representation of a Block.
Definition: schematic.hpp:29
void smash_symbol(Sheet *sheet, SchematicSymbol *sym)
Turns sym's texts to regular text objects.
Definition: schematic.cpp:331
void unsmash_symbol(Sheet *sheet, SchematicSymbol *sym)
Undoes what smash_symbol did.
Definition: schematic.cpp:364
void autoconnect_symbol(Sheet *sheet, SchematicSymbol *sym)
Connects unconnected pins of sym to Nets specified by junctions coincident with pins.
Definition: schematic.cpp:107
void update_refs()
objects owned by the Sheets may hold pointers to other objects of the same sheet or the Block associa...
Definition: schematic.cpp:1321
void disconnect_symbol(Sheet *sheet, SchematicSymbol *sym)
Removes all connections from sym and connects the dangling net lines to junctions.
Definition: schematic.cpp:268
void expand(bool careful=false, const class IInstanceMappingProvider *inst_map=nullptr)
This is where the magic happens.
Definition: schematic.cpp:866
Definition: sheet.hpp:42
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62
Definition: schematic.hpp:142