OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
EdaDataFile.h
1#pragma once
2
3#include <filesystem>
4#include <string>
5#include <vector>
6#include <map>
7#include "../../odbdesign_export.h"
8#include "../../enums.h"
9#include "edadatafile.pb.h"
10#include "common.pb.h"
11#include "../../IProtoBuffable.h"
12#include "PropertyRecord.h"
13#include "ContourPolygon.h"
14#include "AttributeLookupTable.h"
15#include "../IStreamSaveable.h"
16
17
18namespace Odb::Lib::FileModel::Design
19{
20 class ODBDESIGN_EXPORT EdaDataFile : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile>, public IStreamSaveable
21 {
22 public:
23 EdaDataFile(bool logAllLineParsing = false);
25
26 const std::filesystem::path& GetPath() const;
27 const std::filesystem::path& GetDirectory() const;
28 const std::string& GetUnits() const;
29 const std::string& GetSource() const;
30
31 bool Parse(std::filesystem::path path);
32 // Inherited via IStreamSaveable
33 bool Save(std::ostream& os) override;
34
35 struct ODBDESIGN_EXPORT FeatureIdRecord : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord>
36 {
37 enum class Type
38 {
39 Copper,
40 Laminate,
41 Hole
42 };
43
44 typedef std::vector<std::shared_ptr<FeatureIdRecord>> Vector;
45
46 Type type;
47 unsigned int layerNumber;
48 unsigned int featureNumber;
49
50 // Inherited via IProtoBuffable
51 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord> to_protobuf() const override;
52 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord& message) override;
53 };
54
55 struct ODBDESIGN_EXPORT NetRecord : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::NetRecord>, public AttributeLookupTable
56 {
57 struct ODBDESIGN_EXPORT SubnetRecord final : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord>
58 {
59 // common subnet enums
60 enum class Type
61 {
62 Via,
63 Trace,
64 Plane,
65 Toeprint
66 };
67
68 // Plane subnet type enums
69 enum class FillType
70 {
71 Solid,
72 Outline
73 };
74
75 enum class CutoutType
76 {
77 Circle,
78 Rectangle,
79 Octagon,
80 Exact
81 };
82
83 typedef std::vector<std::shared_ptr<SubnetRecord>> Vector;
84
86
87 // common subnet fields
88 Type type;
89 FeatureIdRecord::Vector m_featureIdRecords;
90
91 // Toeprint subnet type fields
92 BoardSide side;
93 unsigned int componentNumber; // component index in the layer components/placements file
94 unsigned toeprintNumber; // toeprint index of component reference in the layer components/placements file
95
96 // Plane subnet type fields
97 FillType fillType;
98 CutoutType cutoutType;
99 double fillSize;
100 unsigned int index;
101
102 inline static const std::string RECORD_TOKEN = "SNT";
103 inline static const std::string RECORD_TYPE_TRACE_TOKEN = "TRC";
104 inline static const std::string RECORD_TYPE_VIA_TOKEN = "VIA";
105 inline static const std::string RECORD_TYPE_TOEPRINT_TOKEN = "TOP";
106 inline static const std::string RECORD_TYPE_PLANE_TOKEN = "PLN";
107
108 // Inherited via IProtoBuffable
109 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord> to_protobuf() const override;
110 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord& message) override;
111
112 }; // SubnetRecord
113
114 typedef std::vector<std::shared_ptr<NetRecord>> Vector;
115 typedef std::map<std::string, std::shared_ptr<NetRecord>> StringMap;
116
117 ~NetRecord();
118
119 std::string name;
120 unsigned int index;
121
122 SubnetRecord::Vector m_subnetRecords;
123 PropertyRecord::Vector m_propertyRecords;
124
125 // Inherited via IProtoBuffable
126 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord> to_protobuf() const override;
127 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::NetRecord& message) override;
128
129 }; // NetRecord
130
131 struct ODBDESIGN_EXPORT PackageRecord : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::PackageRecord>, public AttributeLookupTable
132 {
133 struct ODBDESIGN_EXPORT OutlineRecord : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord>
134 {
135 enum class Type
136 {
137 Rectangle,
138 Circle,
139 Square,
140 Contour
141 };
142
143 typedef std::vector<std::shared_ptr<OutlineRecord>> Vector;
144
146 {
147 m_contourPolygons.clear();
148 }
149
150 Type type;
151
152 // Rectangle
153 double lowerLeftX;
154 double lowerLeftY;
155 double width;
156 double height;
157
158 // Square/Circle
159 double xCenter;
160 double yCenter;
161
162 // Square
163 double halfSide;
164 // Circle
165 double radius;
166
167 ContourPolygon::Vector m_contourPolygons;
168
169 // Inherited via IProtoBuffable
170 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord> to_protobuf() const override;
171 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord& message) override;
172
173 inline static const char* RECTANGLE_RECORD_TOKEN = "RC";
174 inline static const char* CIRCLE_RECORD_TOKEN = "CR";
175 inline static const char* SQUARE_RECORD_TOKEN = "SQ";
176 inline static const char* CONTOUR_BEGIN_RECORD_TOKEN = "CT";
177 inline static const char* CONTOUR_END_RECORD_TOKEN = "CE";
178
179 }; // struct OutlineRecord
180
181 struct ODBDESIGN_EXPORT PinRecord : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord>
182 {
183 enum class Type
184 {
185 ThroughHole,
186 Blind,
187 Surface
188 };
189
190 enum class ElectricalType
191 {
192 Electrical,
193 NonElectrical,
194 Undefined
195 };
196
197 enum class MountType
198 {
199 Smt,
200 RecommendedSmtPad,
201 MT_ThroughHole,
202 RecommendedThroughHole,
203 Pressfit,
204 NonBoard,
205 Hole,
206 MT_Undefined // default
207 };
208
209 typedef std::vector<std::shared_ptr<PinRecord>> Vector;
210 typedef std::map<std::string, std::shared_ptr<PinRecord>> StringMap;
211
212 ~PinRecord()
213 {
214 m_outlineRecords.clear();
215 }
216
217 std::string name;
218 Type type;
219 double xCenter;
220 double yCenter;
221 double finishedHoleSize; // unused, set to 0
222 ElectricalType electricalType;
223 MountType mountType;
224 unsigned int id;
225 unsigned int index;
226
227 OutlineRecord::Vector m_outlineRecords;
228
229 // Inherited via IProtoBuffable
230 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord> to_protobuf() const override;
231 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord& message) override;
232
233 }; // PinRecord
234
235 typedef std::vector<std::shared_ptr<PackageRecord>> Vector;
236 typedef std::map<std::string, std::shared_ptr<PackageRecord>> StringMap;
237
239 {
240 m_outlineRecords.clear();
241 m_pinRecords.clear();
242 m_pinRecordsByName.clear();
243 m_propertyRecords.clear();
244 }
245
246 std::string name;
247 double pitch;
248 double xMin, yMin;
249 double xMax, yMax;
250 unsigned int index;
251
252 OutlineRecord::Vector m_outlineRecords;
253 PinRecord::Vector m_pinRecords;
254 PinRecord::StringMap m_pinRecordsByName;
255 PropertyRecord::Vector m_propertyRecords;
256
257 // Inherited via IProtoBuffable
258 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord> to_protobuf() const override;
259 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::PackageRecord& message) override;
260
261 }; // PackageRecord
262
263 struct FeatureGroupRecord : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord>
264 {
266 {
267 m_propertyRecords.clear();
268 m_featureIdRecords.clear();
269 }
270
271 std::string type; // always "TEXT" per spec
272
273 PropertyRecord::Vector m_propertyRecords;
274 FeatureIdRecord::Vector m_featureIdRecords;
275
276 typedef std::shared_ptr<FeatureGroupRecord> shared_ptr;
277 typedef std::vector<FeatureGroupRecord::shared_ptr> Vector;
278
279 // Inherited via IProtoBuffable
280 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord> to_protobuf() const override;
281 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord& message) override;
282
283 }; // FeatureGroupRecord
284
285 const std::vector<std::string>& GetLayerNames() const;
286 const std::vector<std::string>& GetAttributeNames() const;
287 const std::vector<std::string>& GetAttributeTextValues() const;
288
289 const NetRecord::Vector& GetNetRecords() const;
290 const NetRecord::StringMap& GetNetRecordsByName() const;
291 const PackageRecord::Vector& GetPackageRecords() const;
292 const PackageRecord::StringMap& GetPackageRecordsByName() const;
293 const FeatureGroupRecord::Vector& GetFeatureGroupRecords() const;
294 const PropertyRecord::Vector& GetPropertyRecords() const;
295
296 // Inherited via IProtoBuffable
297 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile> to_protobuf() const override;
298 void from_protobuf(const Odb::Lib::Protobuf::EdaDataFile& message) override;
299
300 private:
301 std::filesystem::path m_directory;
302 std::filesystem::path m_path;
303 std::string m_units;
304
305 std::string m_source;
306 std::vector<std::string> m_layerNames;
307
308 std::vector<std::string> m_attributeNames;
309 std::vector<std::string> m_attributeTextValues;
310
311 NetRecord::Vector m_netRecords;
312 NetRecord::StringMap m_netRecordsByName;
313
314 PackageRecord::Vector m_packageRecords;
315 PackageRecord::StringMap m_packageRecordsByName;
316
317 FeatureGroupRecord::Vector m_featureGroupRecords;
318
319 PropertyRecord::Vector m_propertyRecords;
320
321 bool m_logAllLineParsing;
322
323 inline static const char* EDADATA_FILENAME = "data";
324
325 inline static const char* COMMENT_TOKEN = "#";
326 inline static const char* UNITS_TOKEN = "UNITS";
327 inline static const char* HEADER_RECORD_TOKEN = "HDR";
328 inline static const char* LAYER_NAMES_RECORD_TOKEN = "LYR";
329 inline static const char* PROPERTY_RECORD_TOKEN = "PRP";
330 inline static const char* ATTRIBUTE_NAME_TOKEN = "@";
331 inline static const char* ATTRIBUTE_VALUE_TOKEN = "&";
332 inline static const char* NET_RECORD_TOKEN = "NET";
333 inline static const char* FEATURE_ID_RECORD_TOKEN = "FID";
334 inline static const char* PACKAGE_RECORD_TOKEN = "PKG";
335 inline static const char* PIN_RECORD_TOKEN = "PIN";
336
337 inline static const char* FEATURE_GROUP_RECORD_TOKEN = "FGR";
338
339 }; // EdaDataFile
340
341 //EXPIMP_TEMPLATE template class ODBDESIGN_EXPORT std::vector<std::shared_ptr<EdaData::NetRecord>>;
342 //EXPIMP_TEMPLATE template class ODBDESIGN_EXPORT std::map<std::string, std::shared_ptr<EdaData::NetRecord>>;
343}