OdbDesignLib
OdbDesign ODB++ Parsing Library
ComponentsFile.h
1 #pragma once
2 
3 #include <string>
4 #include <map>
5 #include <memory>
6 #include <filesystem>
7 #include <vector>
8 #include "../../odbdesign_export.h"
9 #include "../../enums.h"
10 #include "../../IProtoBuffable.h"
11 #include "PropertyRecord.h"
12 #include "../../ProtoBuf/componentsfile.pb.h"
13 #include "AttributeLookupTable.h"
14 
15 
16 namespace Odb::Lib::FileModel::Design
17 {
18  class ODBDESIGN_EXPORT ComponentsFile : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile>
19  {
20  public:
22  ~ComponentsFile();
23 
24  bool Parse(std::filesystem::path directory);
25 
26  std::string GetUnits() const;
27  BoardSide GetSide() const;
28  std::filesystem::path GetPath();
29  std::filesystem::path GetDirectory();
30  std::string GetLayerName() const;
31 
32  struct ComponentRecord : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord>, public AttributeLookupTable
33  {
34  ~ComponentRecord();
35 
36  // data members
37  unsigned int pkgRef; // reference number of PKG in eda/data file
38  float locationX;
39  float locationY;
40  float rotation;
41  bool mirror;
42  std::string compName; // refDes
43  std::string partName;
44  //std::string attributes;
45  unsigned int id;
46  // TODO: deal with index of records
47  unsigned int index;
48 
49  // constants
50  constexpr inline static const char* RECORD_TOKEN = "CMP";
51 
52  // typedefs
53  typedef std::map<std::string, std::shared_ptr<ComponentRecord>> StringMap;
54  typedef std::vector<std::shared_ptr<ComponentRecord>> Vector;
55 
56  struct ToeprintRecord : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord::ToeprintRecord>
57  {
58  // TODO: use pinNumber
59  unsigned int pinNumber; // what does this refer to? own pin # or packages pin #?
60  float locationX;
61  float locationY;
62  float rotation;
63  bool mirror;
64  unsigned int netNumber; // net number of NET in eda/data file
65  unsigned int subnetNumber; // subnet number of NET in eda/data file
66  std::string name; // pin name
67 
68  // constants
69  constexpr inline static const char* RECORD_TOKEN = "TOP";
70 
71  // typedefs
72  typedef std::map<std::string, std::shared_ptr<ToeprintRecord>> StringMap;
73  typedef std::vector<std::shared_ptr<ToeprintRecord>> Vector;
74 
75  // Inherited via IProtoBuffable
76  std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord::ToeprintRecord> to_protobuf() const override;
77  void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile::ComponentRecord::ToeprintRecord& message) override;
78  };
79 
80  PropertyRecord::Vector m_propertyRecords;
81  ToeprintRecord::Vector m_toeprintRecords;
82 
83  // Inherited via IProtoBuffable
84  std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord> to_protobuf() const override;
85  void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile::ComponentRecord& message) override;
86 
87  }; // ComponentRecord
88 
89  struct BomDescriptionRecord : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord>
90  {
91  std::string cpn;
92  std::string pkg;
93  std::string ipn;
94  std::vector<std::string> descriptions;
95  std::string vpl_vnd;
96  std::string vpl_mpn;
97  std::string vnd;
98  std::string mpn;
99 
100  // Inherited via IProtoBuffable
101  std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord> to_protobuf() const override;
102  void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord& message) override;
103 
104  typedef std::vector<std::shared_ptr<BomDescriptionRecord>> Vector;
105  typedef std::map<std::string, std::shared_ptr<BomDescriptionRecord>> StringMap;
106 
107  inline static const char* CPN_RECORD_TOKEN = "CPN";
108  inline static const char* PKG_RECORD_TOKEN = "PKG";
109  inline static const char* IPN_RECORD_TOKEN = "IPN";
110  inline static const char* DSC_RECORD_TOKEN = "DSC";
111  inline static const char* VPL_VND_RECORD_TOKEN = "VPL_VND";
112  inline static const char* VPL_MPN_RECORD_TOKEN = "VPL_MPN";
113  inline static const char* VND_RECORD_TOKEN = "VND";
114  inline static const char* MPN_RECORD_TOKEN = "MPN";
115 
116  }; // BomDescriptionRecord
117 
118  const ComponentRecord::Vector& GetComponentRecords() const;
119  const ComponentRecord::StringMap& GetComponentRecordsByName() const;
120  const std::vector<std::string>& GetAttributeNames() const;
121  const std::vector<std::string>& GetAttributeTextValues() const;
122  const BomDescriptionRecord::StringMap& GetBomDescriptionRecordsByCpn() const;
123 
124  constexpr inline static const char* TOP_COMPONENTS_LAYER_NAME = "comp_+_top";
125  constexpr inline static const char* BOTTOM_COMPONENTS_LAYER_NAME = "comp_+_bot";
126 
127  // Inherited via IProtoBuffable
128  std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile> to_protobuf() const override;
129  void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile& message) override;
130 
131  private:
132  std::string m_units;
133  unsigned int m_id;
134  BoardSide m_side;
135  std::string m_layerName;
136  std::filesystem::path m_path;
137  std::filesystem::path m_directory;
138 
139  std::vector<std::string> m_attributeNames;
140  std::vector<std::string> m_attributeTextValues;
141 
142  ComponentRecord::Vector m_componentRecords;
143  // TODO: add records to maps by name while adding to their vectors
144  ComponentRecord::StringMap m_componentRecordsByName;
145 
146  BomDescriptionRecord::StringMap m_bomDescriptionRecordsByCpn;
147 
148  const bool m_allowToepintNetNumbersOfNegative1 = true;
149 
150  constexpr inline static const char* COMPONENTS_FILENAMES[] =
151  {
152  "components",
153  "components2",
154  "components3"
155  };
156 
157  constexpr inline static const char* UNITS_TOKEN = "UNITS";
158  constexpr inline static const char* ID_TOKEN = "ID";
159  constexpr inline static const char* ATTRIBUTE_NAME_TOKEN = "@";
160  constexpr inline static const char* ATTRIBUTE_VALUE_TOKEN = "&";
161  constexpr inline static const char* COMMENT_TOKEN = "#";
162 
163  // TODO: deal with BOM DATA section lines later
164  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_CPN = "CPN";
165  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_PKG = "PKG";
166  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_IPN = "IPN";
167  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_DSC = "DSC";
168  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_VND = "VPL_VND";
169  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_MPN = "VPL_MPN";
170  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VND = "VND";
171  constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_MPN = "MPN";
172 };
173 }