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 <fstream>
13 #include "util/file_version.hpp"
14 #include "util/template_util.hpp"
15 
16 namespace horizon {
17 using json = nlohmann::json;
18 
30 class Schematic {
31 private:
32  unsigned int update_nets();
33 
34 public:
35  Schematic(const UUID &uu, const json &, Block &block, class IPool &pool,
37  static Schematic new_from_file(const std::string &filename, Block &block, IPool &pool,
39  Schematic(const UUID &uu, Block &block);
40  static unsigned int get_app_version();
41 
47  void expand(bool careful = false, const class IInstanceMappingProvider *inst_map = nullptr);
48  void expand_connectivity(bool carful = false);
49 
50  Schematic(const Schematic &sch);
51  void operator=(const Schematic &sch) = delete;
60  void update_refs();
61 
66  void disconnect_symbol(Sheet *sheet, SchematicSymbol *sym);
67 
72  void autoconnect_symbol(Sheet *sheet, SchematicSymbol *sym);
73  void autoconnect_block_symbol(Sheet *sheet, SchematicBlockSymbol *sym);
74 
78  void smash_symbol(Sheet *sheet, SchematicSymbol *sym);
79 
83  void unsmash_symbol(Sheet *sheet, SchematicSymbol *sym);
84 
85  bool delete_net_line(Sheet *sheet, LineNet *line);
86 
87  bool place_bipole_on_line(Sheet *sheet, SchematicSymbol *sym);
88 
89  void swap_gates(const UUID &comp, const UUID &g1, const UUID &g2);
90 
91  void disconnect_block_symbol(Sheet *sheet, SchematicBlockSymbol *sym);
92 
93  std::map<UUIDPath<2>, std::string> get_unplaced_gates() const;
94 
95  Sheet &add_sheet();
96  void delete_sheet(const UUID &uu);
97  Sheet &get_sheet_at_index(unsigned int index);
98  const Sheet &get_sheet_at_index(unsigned int index) const;
99 
100  static Glib::RefPtr<Glib::Regex> get_sheetref_regex();
101 
102  UUID uuid;
103  Block *block;
104  std::string name;
105  std::map<UUID, Sheet> sheets;
106  SchematicRules rules;
107  bool group_tag_visible = false;
108 
109 
110  class Annotation {
111  public:
112  Annotation(const json &j);
113  Annotation();
114  enum class Order { RIGHT_DOWN, DOWN_RIGHT };
115  Order order = Order::RIGHT_DOWN;
116 
117  enum class Mode { SEQUENTIAL, SHEET_100, SHEET_1000 };
118  Mode mode = Mode::SHEET_100;
119 
120  bool fill_gaps = true;
121  bool keep = true;
122  bool ignore_unknown = false;
123  json serialize() const;
124  };
125 
126  Annotation annotation;
127  void annotate();
128 
129  class SheetMapping {
130  public:
131  std::map<UUIDVec, unsigned int> sheet_numbers;
132  unsigned int sheet_total;
133  void update(const Schematic &sch);
134 
135  private:
136  void update(const Schematic &sch, const UUIDVec &instance_path);
137  unsigned int index;
138  };
139  SheetMapping sheet_mapping;
140 
141  void update_sheet_mapping();
142 
143  template <bool c> struct SheetItem {
144  SheetItem(make_const_ref_t<c, Sheet> sh, unsigned int i, make_const_ref_t<c, Schematic> sch, const UUIDVec &p)
145  : sheet(sh), sheet_index(i), schematic(sch), instance_path(p)
146  {
147  }
148  make_const_ref_t<c, Sheet> sheet;
149  unsigned int sheet_index;
150  make_const_ref_t<c, Schematic> schematic;
151  UUIDVec instance_path;
152  };
153 
154  std::vector<SheetItem<false>> get_all_sheets();
155  std::vector<SheetItem<true>> get_all_sheets() const;
156 
157  PDFExportSettings pdf_export_settings;
158 
159  FileVersion version;
160 
161  json serialize() const;
162  void load_pictures(const std::string &dir);
163 
164  ItemSet get_pool_items_used() const;
165 
166  std::vector<Sheet *> get_sheets_sorted();
167  std::vector<const Sheet *> get_sheets_sorted() const;
168 
169 private:
170  void expand_frames(const IInstanceMappingProvider *inst_map);
171 };
172 } // 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:17
Definition: schematic.hpp:110
Definition: schematic.hpp:129
A Schematic is the visual representation of a Block.
Definition: schematic.hpp:30
void smash_symbol(Sheet *sheet, SchematicSymbol *sym)
Turns sym's texts to regular text objects.
Definition: schematic.cpp:330
void unsmash_symbol(Sheet *sheet, SchematicSymbol *sym)
Undoes what smash_symbol did.
Definition: schematic.cpp:363
void autoconnect_symbol(Sheet *sheet, SchematicSymbol *sym)
Connects unconnected pins of sym to Nets specified by junctions coincident with pins.
Definition: schematic.cpp:106
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:1278
void disconnect_symbol(Sheet *sheet, SchematicSymbol *sym)
Removes all connections from sym and connects the dangling net lines to junctions.
Definition: schematic.cpp:267
void expand(bool careful=false, const class IInstanceMappingProvider *inst_map=nullptr)
This is where the magic happens.
Definition: schematic.cpp:823
Definition: sheet.hpp:40
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:143