Horizon
part.hpp
1 #pragma once
2 #include "util/uuid.hpp"
3 #include "util/uuid_ptr.hpp"
4 #include <map>
5 #include <set>
6 #include "entity.hpp"
7 #include "package.hpp"
8 #include "nlohmann/json_fwd.hpp"
9 #include "util/file_version.hpp"
10 #include "util/item_set.hpp"
11 
12 namespace horizon {
13 using json = nlohmann::json;
14 
15 class Part {
16 private:
17  Part(const UUID &uu, const json &j, class IPool &pool);
18  const std::string empty;
19 
20 public:
21  class PadMapItem {
22  public:
23  PadMapItem(const class Gate *g, const class Pin *p) : gate(g), pin(p)
24  {
25  }
28  };
29  Part(const UUID &uu);
30 
31  static Part new_from_json(const json &j, IPool &pool);
32  static Part new_from_file(const std::string &filename, IPool &pool);
33  static unsigned int get_app_version();
34  UUID uuid;
35 
36  enum class Attribute { MPN, VALUE, MANUFACTURER, DATASHEET, DESCRIPTION };
37  std::map<Attribute, std::pair<bool, std::string>> attributes;
38  std::map<UUID, std::string> orderable_MPNs;
39  const std::string &get_attribute(Attribute a) const;
40  const std::pair<bool, std::string> &get_attribute_pair(Attribute a) const;
41 
42  const std::string &get_MPN() const;
43  const std::string &get_value() const;
44  const std::string &get_manufacturer() const;
45  const std::string &get_datasheet() const;
46  const std::string &get_description() const;
47  std::set<std::string> get_tags() const;
48  UUID get_model() const;
49 
50  std::set<std::string> tags;
51  bool inherit_tags = false;
54  UUID model;
55  bool inherit_model = true;
57 
58  void update_refs(IPool &pool);
59  UUID get_uuid() const;
60 
61  std::map<std::string, std::string> parametric;
62  class Column {
63  public:
64  Column(const std::string &d, const std::string &v) : display_name(d), value(v)
65  {
66  }
67  const std::string display_name;
68  const std::string value;
69  };
70  std::map<std::string, Column> parametric_formatted;
71 
72  std::map<UUID, PadMapItem> pad_map;
73 
74  enum class FlagState { SET, CLEAR, INHERIT };
75  enum class Flag { EXCLUDE_BOM, EXCLUDE_PNP, BASE_PART };
76  std::map<Flag, FlagState> flags;
77  bool get_flag(Flag fl) const;
78 
79  enum class OverridePrefix { NO, YES, INHERIT };
80  OverridePrefix override_prefix = OverridePrefix::NO;
81  std::string prefix;
82  const std::string &get_prefix() const;
83 
84  ItemSet get_pool_items_used() const;
85 
86  unsigned int get_required_version() const;
87 
88  FileVersion version;
89 
90  json serialize() const;
91 };
92 } // namespace horizon
Definition: gate.hpp:10
Definition: ipool.hpp:14
Definition: part.hpp:62
Definition: part.hpp:21
Definition: part.hpp:15
A Pin represents a logical pin of a Unit.
Definition: unit.hpp:16
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: uuid_ptr.hpp:8
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62