OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
ComponentsFile.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <map>
5#include <optional>
6#include <memory>
7#include <filesystem>
8#include <vector>
9#include "../../odbdesign_export.h"
10#include "../../enums.h"
11#include "../../IProtoBuffable.h"
12#include "PropertyRecord.h"
13#include "componentsfile.pb.h"
15#include "../IStreamSaveable.h"
16
17
19{
20 class ODBDESIGN_EXPORT ComponentsFile : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile>, public IStreamSaveable
21 {
22 public:
25
26 bool Parse(std::filesystem::path directory);
27 // Inherited via IStreamSaveable
28 bool Save(std::ostream& os) override;
29
30 std::string GetUnits() const;
31 BoardSide GetSide() const;
32 std::filesystem::path GetPath();
33 std::filesystem::path GetDirectory();
34 std::string GetLayerName() const;
35
36 struct ComponentRecord : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord>, public AttributeLookupTable
37 {
39
40 // data members
41 unsigned int pkgRef = 0; // reference number of PKG in eda/data file
42 double locationX = 0.0;
43 double locationY = 0.0;
44 double rotation = 0.0;
45 bool mirror = false;
46 std::string compName; // refDes
47 std::string partName;
48 //std::string attributes;
49 // ODB++ product-model-wide unique id from the CMP record ;ID= trailer.
50 // Optional: absent stays absent (never reported as id 0).
51 std::optional<unsigned int> id;
52 // TODO: deal with index of records
53 unsigned int index = 0;
54
55 // constants
56 constexpr inline static const char* RECORD_TOKEN = "CMP";
57
58 // typedefs
59 typedef std::map<std::string, std::shared_ptr<ComponentRecord>> StringMap;
60 typedef std::vector<std::shared_ptr<ComponentRecord>> Vector;
61
62 struct ToeprintRecord : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord::ToeprintRecord>
63 {
64 // TODO: use pinNumber
65 unsigned int pinNumber = 0; // what does this refer to? own pin # or packages pin #?
66 double locationX = 0.0;
67 double locationY = 0.0;
68 double rotation = 0.0;
69 bool mirror = false;
70 unsigned int netNumber = 0; // net number of NET in eda/data file
71 unsigned int subnetNumber = 0; // subnet number of NET in eda/data file
72 std::string name; // pin name
73
74 // constants
75 constexpr inline static const char* RECORD_TOKEN = "TOP";
76
77 // typedefs
78 typedef std::map<std::string, std::shared_ptr<ToeprintRecord>> StringMap;
79 typedef std::vector<std::shared_ptr<ToeprintRecord>> Vector;
80
81 // Inherited via IProtoBuffable
82 std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord::ToeprintRecord> to_protobuf() const override;
83 void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile::ComponentRecord::ToeprintRecord& message) override;
84 };
85
88
89 // Inherited via IProtoBuffable
90 std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::ComponentRecord> to_protobuf() const override;
91 void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile::ComponentRecord& message) override;
92
93 }; // ComponentRecord
94
95 struct BomDescriptionRecord : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord>
96 {
97 std::string cpn;
98 std::string pkg;
99 std::string ipn;
100 std::vector<std::string> descriptions;
101 std::string vpl_vnd;
102 std::string vpl_mpn;
103 std::string vnd;
104 std::string mpn;
105
106 // Inherited via IProtoBuffable
107 std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord> to_protobuf() const override;
108 void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord& message) override;
109
110 typedef std::vector<std::shared_ptr<BomDescriptionRecord>> Vector;
111 typedef std::map<std::string, std::shared_ptr<BomDescriptionRecord>> StringMap;
112
113 inline static const char* CPN_RECORD_TOKEN = "CPN";
114 inline static const char* PKG_RECORD_TOKEN = "PKG";
115 inline static const char* IPN_RECORD_TOKEN = "IPN";
116 inline static const char* DSC_RECORD_TOKEN = "DSC";
117 inline static const char* VPL_VND_RECORD_TOKEN = "VPL_VND";
118 inline static const char* VPL_MPN_RECORD_TOKEN = "VPL_MPN";
119 inline static const char* VND_RECORD_TOKEN = "VND";
120 inline static const char* MPN_RECORD_TOKEN = "MPN";
121
122 }; // BomDescriptionRecord
123
124 const ComponentRecord::Vector& GetComponentRecords() const;
125 const std::vector<std::string>& GetAttributeNames() const;
126 const std::vector<std::string>& GetAttributeTextValues() const;
127 const BomDescriptionRecord::StringMap& GetBomDescriptionRecordsByCpn() const;
128
129 constexpr inline static const char* TOP_COMPONENTS_LAYER_NAME = "comp_+_top";
130 constexpr inline static const char* BOTTOM_COMPONENTS_LAYER_NAME = "comp_+_bot";
131
132 // Inherited via IProtoBuffable
133 std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile> to_protobuf() const override;
134 void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile& message) override;
135
136 private:
137 std::string m_units;
138 unsigned int m_id;
139 BoardSide m_side;
140 std::string m_layerName;
141 std::filesystem::path m_path;
142 std::filesystem::path m_directory;
143
144 std::vector<std::string> m_attributeNames;
145 std::vector<std::string> m_attributeTextValues;
146
147 ComponentRecord::Vector m_componentRecords;
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}
BoardSide
Definition enums.h:6
#define ODBDESIGN_EXPORT
std::vector< std::shared_ptr< BomDescriptionRecord > > Vector
std::map< std::string, std::shared_ptr< BomDescriptionRecord > > StringMap
std::map< std::string, std::shared_ptr< ToeprintRecord > > StringMap
std::vector< std::shared_ptr< ComponentRecord > > Vector
std::map< std::string, std::shared_ptr< ComponentRecord > > StringMap
std::vector< std::shared_ptr< PropertyRecord > > Vector