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