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