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