1#include "EdaDataFile.h"
5#include "../../enums.h"
6#include "edadatafile.pb.h"
7#include "ArchiveExtractor.h"
9#include "../parse_info.h"
10#include "../parse_error.h"
11#include "../invalid_odb_error.h"
12#include "../../Text/Utf8Sanitizer.h"
14using namespace std::filesystem;
17namespace Odb::Lib::FileModel::Design
19 EdaDataFile::EdaDataFile(
bool logAllLineParsing)
20 : m_logAllLineParsing(logAllLineParsing)
24 EdaDataFile::~EdaDataFile()
27 m_attributeNames.clear();
28 m_attributeTextValues.clear();
30 m_netRecordsByName.clear();
31 m_packageRecords.clear();
32 m_packageRecordsByName.clear();
33 m_featureGroupRecords.clear();
34 m_propertyRecords.clear();
37 const std::filesystem::path& EdaDataFile::GetPath()
const
42 const std::filesystem::path& EdaDataFile::GetDirectory()
const
47 const std::string& EdaDataFile::GetUnits()
const
52 const std::string& EdaDataFile::GetSource()
const
57 EdaDataFile::NetRecord::SubnetRecord::~SubnetRecord()
59 m_featureIdRecords.clear();
62 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord> EdaDataFile::NetRecord::SubnetRecord::to_protobuf()
const
64 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord> pSubnetRecordMessage(
new Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord);
65 pSubnetRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord::Type) type);
66 if (type == Type::Toeprint)
68 pSubnetRecordMessage->set_componentnumber(componentNumber);
69 pSubnetRecordMessage->set_toeprintnumber(toeprintNumber);
70 pSubnetRecordMessage->set_side((Odb::Lib::Protobuf::BoardSide)side);
72 else if (type == Type::Plane)
74 pSubnetRecordMessage->set_filltype((Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord::FillType)fillType);
75 pSubnetRecordMessage->set_cutouttype((Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord::CutoutType) cutoutType);
76 pSubnetRecordMessage->set_fillsize(fillSize);
79 for (
const auto& featureIdRecord : m_featureIdRecords)
81 auto pFeatureIdRecordMessage = pSubnetRecordMessage->add_featureidrecords();
82 pFeatureIdRecordMessage->CopyFrom(*featureIdRecord->to_protobuf());
84 return pSubnetRecordMessage;
87 void EdaDataFile::NetRecord::SubnetRecord::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord& message)
89 type =
static_cast<Type
>(message.type());
91 if (type == Type::Toeprint)
93 componentNumber = message.componentnumber();
94 toeprintNumber = message.toeprintnumber();
95 side =
static_cast<BoardSide
>(message.side());
97 else if (type == Type::Plane)
99 fillType =
static_cast<FillType
>(message.filltype());
100 cutoutType =
static_cast<CutoutType
>(message.cutouttype());
101 fillSize = message.fillsize();
102 index = message.index();
105 for (
const auto& featureIdRecordMessage : message.featureidrecords())
107 auto pFeatureIdRecord = std::make_shared<FeatureIdRecord>();
108 pFeatureIdRecord->from_protobuf(featureIdRecordMessage);
109 m_featureIdRecords.push_back(pFeatureIdRecord);
113 EdaDataFile::NetRecord::~NetRecord()
115 m_subnetRecords.clear();
116 m_propertyRecords.clear();
119 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord> EdaDataFile::NetRecord::to_protobuf()
const
121 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord> pNetRecordMessage(
new Odb::Lib::Protobuf::EdaDataFile::NetRecord);
122 pNetRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
124 pNetRecordMessage->set_index(index);
126 for (
const auto& propertyRecord : m_propertyRecords)
128 auto pPropertyRecordMessage = pNetRecordMessage->add_propertyrecords();
129 pPropertyRecordMessage->CopyFrom(*propertyRecord->to_protobuf());
132 for (
const auto& subnetRecord : m_subnetRecords)
134 auto pSubnetRecordMessage = pNetRecordMessage->add_subnetrecords();
135 pSubnetRecordMessage->CopyFrom(*subnetRecord->to_protobuf());
137 for (
const auto& kvAttributeAssignment : m_attributeLookupTable)
139 (*pNetRecordMessage->mutable_attributelookuptable())[Odb::Lib::Text::ToUtf8(kvAttributeAssignment.first)] =
Odb::Lib::Text::ToUtf8(kvAttributeAssignment.second);
141 return pNetRecordMessage;
144 void EdaDataFile::NetRecord::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile::NetRecord& message)
146 name = message.name();
148 index = message.index();
150 for (
const auto& propertyRecordMessage : message.propertyrecords())
152 auto pPropertyRecord = std::make_shared<PropertyRecord>();
153 pPropertyRecord->from_protobuf(propertyRecordMessage);
154 m_propertyRecords.push_back(pPropertyRecord);
157 for (
const auto& subnetRecordMessage : message.subnetrecords())
159 auto pSubnetRecord = std::make_shared<SubnetRecord>();
160 pSubnetRecord->from_protobuf(subnetRecordMessage);
161 m_subnetRecords.push_back(pSubnetRecord);
164 for (
const auto& kvAttributeAssignment : message.attributelookuptable())
166 m_attributeLookupTable[kvAttributeAssignment.first] = kvAttributeAssignment.second;
170 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord>
171 EdaDataFile::FeatureIdRecord::to_protobuf()
const
173 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord> pFeatureIdRecordMessage(
new Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord);
174 pFeatureIdRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord::Type) type);
175 pFeatureIdRecordMessage->set_layernumber(layerNumber);
176 pFeatureIdRecordMessage->set_featurenumber(featureNumber);
177 return pFeatureIdRecordMessage;
180 void EdaDataFile::FeatureIdRecord::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord& message)
182 type =
static_cast<Type
>(message.type());
183 layerNumber = message.layernumber();
184 featureNumber = message.featurenumber();
187 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord>
188 EdaDataFile::FeatureGroupRecord::to_protobuf()
const
190 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord> pFeatureGroupRecordMessage(
new Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord);
191 pFeatureGroupRecordMessage->set_type(Odb::Lib::Text::ToUtf8(type));
192 for (
const auto& featureIdRecord : m_featureIdRecords)
194 auto pFeatureIdRecordMessage = pFeatureGroupRecordMessage->add_featureidrecords();
195 pFeatureIdRecordMessage->CopyFrom(*featureIdRecord->to_protobuf());
197 for (
const auto& propertyRecord : m_propertyRecords)
199 auto pPropertyRecordMessage = pFeatureGroupRecordMessage->add_featureidrecords();
200 pPropertyRecordMessage->CopyFrom(*propertyRecord->to_protobuf());
202 return pFeatureGroupRecordMessage;
205 void EdaDataFile::FeatureGroupRecord::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord& message)
207 type = message.type();
208 for (
const auto& featureIdRecordMessage : message.featureidrecords())
210 auto pFeatureIdRecord = std::make_shared<FeatureIdRecord>();
211 pFeatureIdRecord->from_protobuf(featureIdRecordMessage);
212 m_featureIdRecords.push_back(pFeatureIdRecord);
214 for (
const auto& propertyRecordMessage : message.propertyrecords())
216 auto pPropertyRecord = std::make_shared<PropertyRecord>();
217 pPropertyRecord->from_protobuf(propertyRecordMessage);
218 m_propertyRecords.push_back(pPropertyRecord);
222 const std::vector<std::string>& EdaDataFile::GetLayerNames()
const
227 const std::vector<std::string>& EdaDataFile::GetAttributeNames()
const
229 return m_attributeNames;
232 const std::vector<std::string>& EdaDataFile::GetAttributeTextValues()
const
234 return m_attributeTextValues;
237 const EdaDataFile::NetRecord::Vector& EdaDataFile::GetNetRecords()
const
242 const EdaDataFile::NetRecord::StringMap& EdaDataFile::GetNetRecordsByName()
const
244 return m_netRecordsByName;
247 const EdaDataFile::PackageRecord::Vector& EdaDataFile::GetPackageRecords()
const
249 return m_packageRecords;
252 const EdaDataFile::PackageRecord::StringMap& EdaDataFile::GetPackageRecordsByName()
const
254 return m_packageRecordsByName;
257 const EdaDataFile::FeatureGroupRecord::Vector& EdaDataFile::GetFeatureGroupRecords()
const
259 return m_featureGroupRecords;
262 const PropertyRecord::Vector& EdaDataFile::GetPropertyRecords()
const
264 return m_propertyRecords;
267 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile> EdaDataFile::to_protobuf()
const
269 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile> pEdaDataFileMessage(
new Odb::Lib::Protobuf::EdaDataFile);
270 pEdaDataFileMessage->set_path(Odb::Lib::Text::ToUtf8(m_path.string()));
271 pEdaDataFileMessage->set_units(Odb::Lib::Text::ToUtf8(m_units));
272 pEdaDataFileMessage->set_source(Odb::Lib::Text::ToUtf8(m_source));
273 for (
const auto& layerName : m_layerNames)
275 pEdaDataFileMessage->add_layernames(Odb::Lib::Text::ToUtf8(layerName));
277 for (
const auto& attributeName : m_attributeNames)
279 pEdaDataFileMessage->add_attributenames(Odb::Lib::Text::ToUtf8(attributeName));
281 for (
const auto& attrTextValue : m_attributeTextValues)
283 pEdaDataFileMessage->add_attributetextvalues(Odb::Lib::Text::ToUtf8(attrTextValue));
285 for (
const auto& pNetRecord : m_netRecords)
287 auto pNetRecordMessage = pEdaDataFileMessage->add_netrecords();
288 pNetRecordMessage->CopyFrom(*pNetRecord->to_protobuf());
290 for (
const auto& kvNetRecord : m_netRecordsByName)
292 (*pEdaDataFileMessage->mutable_netrecordsbyname())[Odb::Lib::Text::ToUtf8(kvNetRecord.first)] = *kvNetRecord.second->to_protobuf();
294 for (
const auto& pPackageRecord : m_packageRecords)
296 auto pPackageRecordMessage = pEdaDataFileMessage->add_packagerecords();
297 pPackageRecordMessage->CopyFrom(*pPackageRecord->to_protobuf());
299 for (
const auto& kvPackageRecord : m_packageRecordsByName)
301 (*pEdaDataFileMessage->mutable_packagerecordsbyname())[Odb::Lib::Text::ToUtf8(kvPackageRecord.first)] = *kvPackageRecord.second->to_protobuf();
303 for (
const auto& pPropertyRecord : m_propertyRecords)
305 auto pPropertyRecordMessage = pEdaDataFileMessage->add_propertyrecords();
306 pPropertyRecordMessage->CopyFrom(*pPropertyRecord->to_protobuf());
308 for (
const auto& pFeatureGroupRecord : m_featureGroupRecords)
310 auto pFeatureGroupRecordMessage = pEdaDataFileMessage->add_featuregrouprecords();
311 pFeatureGroupRecordMessage->CopyFrom(*pFeatureGroupRecord->to_protobuf());
314 return pEdaDataFileMessage;
317 void EdaDataFile::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile& message)
319 m_path = message.path();
320 m_units = message.units();
321 m_source = message.source();
322 for (
const auto& layerName : message.layernames())
324 m_layerNames.push_back(layerName);
326 for (
const auto& attributeName : message.attributenames())
328 m_attributeNames.push_back(attributeName);
330 for (
const auto& attrTextValue : message.attributetextvalues())
332 m_attributeTextValues.push_back(attrTextValue);
334 for (
const auto& netRecordMessage : message.netrecords())
336 auto pNetRecord = std::make_shared<NetRecord>();
337 pNetRecord->from_protobuf(netRecordMessage);
338 m_netRecords.push_back(pNetRecord);
340 for (
const auto& kvNetRecordMessage : message.netrecordsbyname())
342 auto pNetRecord = std::make_shared<NetRecord>();
343 pNetRecord->from_protobuf(kvNetRecordMessage.second);
344 m_netRecordsByName[kvNetRecordMessage.first] = pNetRecord;
346 for (
const auto& packageRecordMessage : message.packagerecords())
348 auto pPackageRecord = std::make_shared<PackageRecord>();
349 pPackageRecord->from_protobuf(packageRecordMessage);
350 m_packageRecords.push_back(pPackageRecord);
352 for (
const auto& kvPackageRecordMessage : message.packagerecordsbyname())
354 auto pPackageRecord = std::make_shared<PackageRecord>();
355 pPackageRecord->from_protobuf(kvPackageRecordMessage.second);
356 m_packageRecordsByName[kvPackageRecordMessage.first] = pPackageRecord;
358 for (
const auto& propertyRecordMessage : message.propertyrecords())
360 auto pPropertyRecord = std::make_shared<PropertyRecord>();
361 pPropertyRecord->from_protobuf(propertyRecordMessage);
362 m_propertyRecords.push_back(pPropertyRecord);
364 for (
const auto& featureGroupRecordMessage : message.featuregrouprecords())
366 auto pFeatureGroupRecord = std::make_shared<FeatureGroupRecord>();
367 pFeatureGroupRecord->from_protobuf(featureGroupRecordMessage);
368 m_featureGroupRecords.push_back(pFeatureGroupRecord);
372 bool EdaDataFile::Save(std::ostream& os)
377 bool EdaDataFile::Parse(std::filesystem::path path)
379 std::ifstream edaDataFile;
385 loginfo(
"checking for extraction...");
388 m_path = ArchiveExtractor::getUncompressedFilePath(m_directory.string(), EDADATA_FILENAME);
390 if (!std::filesystem::exists(m_path))
392 auto message =
"eda/data file does not exist: [" + m_path.string() +
"]";
393 throw invalid_odb_error(message.c_str());
395 else if (!std::filesystem::is_regular_file(m_path))
397 auto message =
"eda/data is not a file: [" + m_path.string() +
"]";
398 throw invalid_odb_error(message.c_str());
401 loginfo(
"any extraction complete, parsing data...");
403 edaDataFile.open(m_path.string(), std::ios::in);
404 if (!edaDataFile.is_open())
406 auto message =
"unable to open eda/data file: [" + m_path.string() +
"]";
407 throw invalid_odb_error(message.c_str());
410 std::shared_ptr<NetRecord> pCurrentNetRecord;
411 std::shared_ptr<NetRecord::SubnetRecord> pCurrentSubnetRecord;
413 std::shared_ptr<PackageRecord> pCurrentPackageRecord;
414 std::shared_ptr<PackageRecord::PinRecord> pCurrentPinRecord;
416 std::shared_ptr<PackageRecord::OutlineRecord> pCurrentContourOutlineRecord;
417 std::shared_ptr<ContourPolygon> pCurrentContourPolygon;
419 FeatureGroupRecord::shared_ptr pCurrentFeatureGroupRecord;
421 while (std::getline(edaDataFile, line))
427 Utils::str_trim(line);
430 if (m_logAllLineParsing)
432 parse_info pi(m_path, line, lineNumber);
433 logdebug(pi.toString(
"Parsing line..."));
436 std::stringstream lineStream(line);
438 if (line.find(ATTRIBUTE_NAME_TOKEN) == 0 ||
439 line.find(std::string(COMMENT_TOKEN) + ATTRIBUTE_NAME_TOKEN) == 0)
444 if (!std::getline(lineStream, token,
' '))
446 throw_parse_error(m_path, line, token, lineNumber);
448 else if (!std::getline(lineStream, token,
' '))
450 throw_parse_error(m_path, line, token, lineNumber);
452 m_attributeNames.push_back(token);
454 else if (line.find(ATTRIBUTE_VALUE_TOKEN) == 0 ||
455 line.find(std::string(COMMENT_TOKEN) + ATTRIBUTE_VALUE_TOKEN) == 0)
459 if (!std::getline(lineStream, token,
' '))
461 throw_parse_error(m_path, line, token, lineNumber);
463 else if (!std::getline(lineStream, token,
' '))
465 throw_parse_error(m_path, line, token, lineNumber);
467 m_attributeTextValues.push_back(token);
469 else if (line.find(COMMENT_TOKEN) == 0)
474 else if (line.find(UNITS_TOKEN) == 0)
478 if (!std::getline(lineStream, token,
'='))
480 throw_parse_error(m_path, line, token, lineNumber);
482 else if (!std::getline(lineStream, token,
'='))
484 throw_parse_error(m_path, line, token, lineNumber);
488 else if (line.find(HEADER_RECORD_TOKEN) == 0)
494 if (token != HEADER_RECORD_TOKEN)
496 throw_parse_error(m_path, line, token, lineNumber);
500 if (!std::getline(lineStream, m_source))
502 throw_parse_error(m_path, line, token, lineNumber);
505 Utils::str_trim(m_source);
507 else if (line.find(LAYER_NAMES_RECORD_TOKEN) == 0)
513 if (token != LAYER_NAMES_RECORD_TOKEN)
515 throw_parse_error(m_path, line, token, lineNumber);
518 while (lineStream >> token)
520 m_layerNames.push_back(token);
523 else if (line.find(PropertyRecord::RECORD_TOKEN) == 0)
527 if (!(lineStream >> token))
529 throw_parse_error(m_path, line, token, lineNumber);
532 if (token != PropertyRecord::RECORD_TOKEN)
534 throw_parse_error(m_path, line, token, lineNumber);
537 auto pPropertyRecord = std::make_shared<PropertyRecord>();
539 if (!(lineStream >> pPropertyRecord->name))
541 throw_parse_error(m_path, line, token, lineNumber);
544 if (!(lineStream >> token))
546 throw_parse_error(m_path, line, token, lineNumber);
555 if (!(lineStream >> token))
557 throw_parse_error(m_path, line, token, lineNumber);
561 if (token.size() > 0 && token[0] ==
'\'')
567 if (token.size() > 0 && token[token.size() - 1] ==
'\'')
570 token.erase(token.size() - 1);
573 Utils::str_trim(token);
576 pPropertyRecord->value = token;
579 while (lineStream >> f)
581 pPropertyRecord->floatValues.push_back(f);
584 if (pCurrentNetRecord !=
nullptr)
586 pCurrentNetRecord->m_propertyRecords.push_back(pPropertyRecord);
588 else if (pCurrentPackageRecord !=
nullptr)
590 pCurrentPackageRecord->m_propertyRecords.push_back(pPropertyRecord);
592 else if (pCurrentFeatureGroupRecord !=
nullptr)
594 pCurrentFeatureGroupRecord->m_propertyRecords.push_back(pPropertyRecord);
599 m_propertyRecords.push_back(pPropertyRecord);
602 else if (line.find(NET_RECORD_TOKEN) == 0)
607 if (!(lineStream >> token))
609 throw_parse_error(m_path, line, token, lineNumber);
612 if (token != NET_RECORD_TOKEN)
614 throw_parse_error(m_path, line, token, lineNumber);
618 if (pCurrentNetRecord !=
nullptr)
621 if (pCurrentSubnetRecord !=
nullptr)
623 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
624 pCurrentSubnetRecord.reset();
627 m_netRecords.push_back(pCurrentNetRecord);
629 pCurrentNetRecord.reset();
633 if (!std::getline(lineStream, token,
';'))
635 throw_parse_error(m_path, line, token, lineNumber);
642 pCurrentNetRecord = std::make_shared<NetRecord>();
643 pCurrentNetRecord->name = token;
644 pCurrentNetRecord->index =
static_cast<unsigned>(m_netRecords.size());
646 std::string attrIdString;
647 lineStream >> attrIdString;
648 if (!pCurrentNetRecord->ParseAttributeLookupTable(attrIdString))
650 throw_parse_error(m_path, line, token, lineNumber);
653 else if (line.find(NetRecord::SubnetRecord::RECORD_TOKEN) == 0)
659 if (token != NetRecord::SubnetRecord::RECORD_TOKEN)
661 throw_parse_error(m_path, line, token, lineNumber);
664 if (pCurrentNetRecord !=
nullptr)
667 if (pCurrentSubnetRecord !=
nullptr)
669 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
670 pCurrentSubnetRecord.reset();
674 pCurrentSubnetRecord = std::make_shared<NetRecord::SubnetRecord>();
675 pCurrentSubnetRecord->index =
static_cast<unsigned>(pCurrentNetRecord->m_subnetRecords.size());
679 if (token == NetRecord::SubnetRecord::RECORD_TYPE_VIA_TOKEN)
681 pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Via;
683 else if (token == NetRecord::SubnetRecord::RECORD_TYPE_TRACE_TOKEN)
685 pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Trace;
687 else if (token == NetRecord::SubnetRecord::RECORD_TYPE_PLANE_TOKEN)
689 pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Plane;
695 pCurrentSubnetRecord->fillType = NetRecord::SubnetRecord::FillType::Solid;
697 else if (token ==
"O")
699 pCurrentSubnetRecord->fillType = NetRecord::SubnetRecord::FillType::Outline;
703 throw_parse_error(m_path, line, token, lineNumber);
710 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Circle;
712 else if (token ==
"R")
714 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Rectangle;
716 else if (token ==
"O")
718 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Octagon;
720 else if (token ==
"E")
722 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Exact;
726 throw_parse_error(m_path, line, token, lineNumber);
730 lineStream >> pCurrentSubnetRecord->fillSize;
732 else if (token == NetRecord::SubnetRecord::RECORD_TYPE_TOEPRINT_TOKEN)
734 pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Toeprint;
740 pCurrentSubnetRecord->side = BoardSide::Top;
742 else if (token ==
"B")
744 pCurrentSubnetRecord->side = BoardSide::Bottom;
748 throw_parse_error(m_path, line, token, lineNumber);
752 lineStream >> pCurrentSubnetRecord->componentNumber;
755 lineStream >> pCurrentSubnetRecord->toeprintNumber;
759 throw_parse_error(m_path, line, token, lineNumber);
762 else if (line.find(FEATURE_ID_RECORD_TOKEN) == 0)
767 if (!(lineStream >> token) || token != FEATURE_ID_RECORD_TOKEN)
769 throw_parse_error(m_path, line, token, lineNumber);
772 auto pFeatureIdRecord = std::make_shared<FeatureIdRecord>();
775 if (!(lineStream >> token))
777 throw_parse_error(m_path, line, token, lineNumber);
782 pFeatureIdRecord->type = FeatureIdRecord::Type::Copper;
784 else if (token ==
"L")
786 pFeatureIdRecord->type = FeatureIdRecord::Type::Laminate;
788 else if (token ==
"H")
790 pFeatureIdRecord->type = FeatureIdRecord::Type::Hole;
794 throw_parse_error(m_path, line, token, lineNumber);
798 if (!(lineStream >> pFeatureIdRecord->layerNumber))
800 throw_parse_error(m_path, line, token, lineNumber);
804 if (!(lineStream >> pFeatureIdRecord->featureNumber))
806 throw_parse_error(m_path, line, token, lineNumber);
809 if (pCurrentNetRecord !=
nullptr &&
810 pCurrentSubnetRecord !=
nullptr)
812 pCurrentSubnetRecord->m_featureIdRecords.push_back(pFeatureIdRecord);
814 else if (pCurrentFeatureGroupRecord !=
nullptr)
816 pCurrentFeatureGroupRecord->m_featureIdRecords.push_back(pFeatureIdRecord);
820 throw_parse_error(m_path, line, token, lineNumber);
823 else if (line.find(PACKAGE_RECORD_TOKEN) == 0)
828 if (!(lineStream >> token) || token != PACKAGE_RECORD_TOKEN)
830 throw_parse_error(m_path, line, token, lineNumber);
834 if (pCurrentNetRecord !=
nullptr)
837 if (pCurrentSubnetRecord !=
nullptr)
839 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
840 pCurrentSubnetRecord.reset();
843 m_netRecords.push_back(pCurrentNetRecord);
845 pCurrentNetRecord.reset();
847 else if (pCurrentPackageRecord !=
nullptr)
850 if (pCurrentPinRecord !=
nullptr)
853 if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
855 throw_parse_error(m_path, line, token, lineNumber);
857 pCurrentPinRecord->index =
static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
858 pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
859 pCurrentPinRecord.reset();
863 m_packageRecords.push_back(pCurrentPackageRecord);
865 pCurrentPackageRecord.reset();
868 pCurrentPackageRecord = std::make_shared<PackageRecord>();
869 pCurrentPackageRecord->index =
static_cast<unsigned int>(m_packageRecords.size());
872 if (!(lineStream >> pCurrentPackageRecord->name))
874 throw_parse_error(m_path, line, token, lineNumber);
878 if (!(lineStream >> pCurrentPackageRecord->pitch))
880 throw_parse_error(m_path, line, token, lineNumber);
884 if (!(lineStream >> pCurrentPackageRecord->xMin >> pCurrentPackageRecord->yMin))
886 throw_parse_error(m_path, line, token, lineNumber);
890 if (!(lineStream >> pCurrentPackageRecord->xMax))
892 throw_parse_error(m_path, line, token, lineNumber);
896 if (!std::getline(lineStream, token,
';'))
898 throw_parse_error(m_path, line, token, lineNumber);
902 pCurrentPackageRecord->yMax = std::stof(token);
904 std::string attrIdString;
905 lineStream >> attrIdString;
906 if (!pCurrentPackageRecord->ParseAttributeLookupTable(attrIdString))
908 throw_parse_error(m_path, line, token, lineNumber);
911 else if (line.find(PIN_RECORD_TOKEN) == 0)
916 if (!(lineStream >> token) || token != PIN_RECORD_TOKEN)
918 throw_parse_error(m_path, line, token, lineNumber);
921 if (pCurrentPackageRecord !=
nullptr)
924 if (pCurrentPinRecord !=
nullptr)
927 if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
929 throw_parse_error(m_path, line, token, lineNumber);
931 pCurrentPinRecord->index =
static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
932 pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
933 pCurrentPinRecord.reset();
937 pCurrentPinRecord = std::make_shared<PackageRecord::PinRecord>();
941 lineStream >> pCurrentPinRecord->name;
944 if (!(lineStream >> token))
946 throw_parse_error(m_path, line, token, lineNumber);
951 pCurrentPinRecord->type = PackageRecord::PinRecord::Type::ThroughHole;
953 else if (token ==
"B")
955 pCurrentPinRecord->type = PackageRecord::PinRecord::Type::Blind;
957 else if (token ==
"S")
959 pCurrentPinRecord->type = PackageRecord::PinRecord::Type::Surface;
963 logerror(
"unknown pin type: [" + token +
"]");
964 throw_parse_error(m_path, line, token, lineNumber);
968 if (!(lineStream >> pCurrentPinRecord->xCenter >> pCurrentPinRecord->yCenter))
970 throw_parse_error(m_path, line, token, lineNumber);
974 if (!(lineStream >> pCurrentPinRecord->finishedHoleSize))
976 throw_parse_error(m_path, line, token, lineNumber);
980 if (!(lineStream >> token))
982 throw_parse_error(m_path, line, token, lineNumber);
987 pCurrentPinRecord->electricalType = PackageRecord::PinRecord::ElectricalType::Electrical;
989 else if (token ==
"M")
991 pCurrentPinRecord->electricalType = PackageRecord::PinRecord::ElectricalType::NonElectrical;
993 else if (token ==
"U")
995 pCurrentPinRecord->electricalType = PackageRecord::PinRecord::ElectricalType::Undefined;
999 logerror(
"unknown pin electrical type: [" + token +
"]");
1000 throw_parse_error(m_path, line, token, lineNumber);
1004 if (!(lineStream >> token))
1006 throw_parse_error(m_path, line, token, lineNumber);
1011 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::Smt;
1013 else if (token ==
"D")
1015 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::RecommendedSmtPad;
1017 else if (token ==
"T")
1019 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::MT_ThroughHole;
1021 else if (token ==
"R")
1023 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::RecommendedThroughHole;
1025 else if (token ==
"P")
1027 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::Pressfit;
1029 else if (token ==
"N")
1031 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::NonBoard;
1033 else if (token ==
"H")
1035 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::Hole;
1037 else if (token ==
"U")
1039 pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::MT_Undefined;
1043 logerror(
"unknown pin mount type: [" + token +
"]");
1044 throw_parse_error(m_path, line, token, lineNumber);
1049 if (lineStream >> token)
1051 std::stringstream idStream(token);
1052 if (!std::getline(idStream, token,
'=') || token !=
"ID")
1054 throw_parse_error(m_path, line, token, lineNumber);
1057 idStream >> pCurrentPinRecord->id;
1062#define SIMULATE_PARSE_ERROR 0
1063#if SIMULATE_PARSE_ERROR
1064 throw_parse_error(m_path, line, token, lineNumber);
1067 pCurrentPinRecord->id = UINT_MAX;
1070 else if (line.find(FEATURE_GROUP_RECORD_TOKEN) == 0)
1075 if (!(lineStream >> token))
1077 throw_parse_error(m_path, line, token, lineNumber);
1080 if (token != FEATURE_GROUP_RECORD_TOKEN)
1082 throw_parse_error(m_path, line, token, lineNumber);
1086 if (pCurrentNetRecord !=
nullptr)
1089 if (pCurrentSubnetRecord !=
nullptr)
1091 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
1092 pCurrentSubnetRecord.reset();
1095 m_netRecords.push_back(pCurrentNetRecord);
1097 pCurrentNetRecord.reset();
1099 else if (pCurrentPackageRecord !=
nullptr)
1102 if (pCurrentPinRecord !=
nullptr)
1105 if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
1107 throw_parse_error(m_path, line, token, lineNumber);
1109 pCurrentPinRecord->index =
static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
1110 pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
1111 pCurrentPinRecord.reset();
1115 m_packageRecords.push_back(pCurrentPackageRecord);
1117 pCurrentPackageRecord.reset();
1119 else if (pCurrentFeatureGroupRecord !=
nullptr)
1121 m_featureGroupRecords.push_back(pCurrentFeatureGroupRecord);
1122 pCurrentFeatureGroupRecord.reset();
1125 pCurrentFeatureGroupRecord = std::make_shared<FeatureGroupRecord>();
1127 if (!(lineStream >> pCurrentFeatureGroupRecord->type))
1129 throw_parse_error(m_path, line, token, lineNumber);
1132 else if (line.find(PackageRecord::OutlineRecord::RECTANGLE_RECORD_TOKEN) == 0)
1135 if (!(lineStream >> token))
1137 throw_parse_error(m_path, line, token, lineNumber);
1140 if (token != PackageRecord::OutlineRecord::RECTANGLE_RECORD_TOKEN)
1142 throw_parse_error(m_path, line, token, lineNumber);
1145 auto pOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
1146 pOutlineRecord->type = PackageRecord::OutlineRecord::Type::Rectangle;
1148 if (!(lineStream >> pOutlineRecord->lowerLeftX))
1150 throw_parse_error(m_path, line, token, lineNumber);
1153 if (!(lineStream >> pOutlineRecord->lowerLeftY))
1155 throw_parse_error(m_path, line, token, lineNumber);
1158 if (!(lineStream >> pOutlineRecord->width))
1160 throw_parse_error(m_path, line, token, lineNumber);
1163 if (!(lineStream >> pOutlineRecord->height))
1165 throw_parse_error(m_path, line, token, lineNumber);
1168 if (pCurrentPackageRecord !=
nullptr)
1170 if (pCurrentPinRecord !=
nullptr)
1172 pCurrentPinRecord->m_outlineRecords.push_back(pOutlineRecord);
1176 pCurrentPackageRecord->m_outlineRecords.push_back(pOutlineRecord);
1181 throw_parse_error(m_path, line, token, lineNumber);
1184 else if (line.find(PackageRecord::OutlineRecord::CIRCLE_RECORD_TOKEN) == 0)
1187 if (!(lineStream >> token))
1189 throw_parse_error(m_path, line, token, lineNumber);
1192 if (token != PackageRecord::OutlineRecord::CIRCLE_RECORD_TOKEN)
1194 throw_parse_error(m_path, line, token, lineNumber);
1197 auto pOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
1198 pOutlineRecord->type = PackageRecord::OutlineRecord::Type::Circle;
1200 if (!(lineStream >> pOutlineRecord->xCenter))
1202 throw_parse_error(m_path, line, token, lineNumber);
1205 if (!(lineStream >> pOutlineRecord->yCenter))
1207 throw_parse_error(m_path, line, token, lineNumber);
1210 if (!(lineStream >> pOutlineRecord->radius))
1212 throw_parse_error(m_path, line, token, lineNumber);
1215 if (pCurrentPackageRecord !=
nullptr)
1217 if (pCurrentPinRecord !=
nullptr)
1219 pCurrentPinRecord->m_outlineRecords.push_back(pOutlineRecord);
1223 pCurrentPackageRecord->m_outlineRecords.push_back(pOutlineRecord);
1228 throw_parse_error(m_path, line, token, lineNumber);
1231 else if (line.find(PackageRecord::OutlineRecord::SQUARE_RECORD_TOKEN) == 0)
1234 if (!(lineStream >> token))
1236 throw_parse_error(m_path, line, token, lineNumber);
1239 if (token != PackageRecord::OutlineRecord::SQUARE_RECORD_TOKEN)
1241 throw_parse_error(m_path, line, token, lineNumber);
1244 auto pOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
1245 pOutlineRecord->type = PackageRecord::OutlineRecord::Type::Square;
1247 if (!(lineStream >> pOutlineRecord->xCenter))
1249 throw_parse_error(m_path, line, token, lineNumber);
1252 if (!(lineStream >> pOutlineRecord->yCenter))
1254 throw_parse_error(m_path, line, token, lineNumber);
1257 if (!(lineStream >> pOutlineRecord->halfSide))
1259 throw_parse_error(m_path, line, token, lineNumber);
1262 if (pCurrentPackageRecord !=
nullptr)
1264 if (pCurrentPinRecord !=
nullptr)
1266 pCurrentPinRecord->m_outlineRecords.push_back(pOutlineRecord);
1270 pCurrentPackageRecord->m_outlineRecords.push_back(pOutlineRecord);
1275 throw_parse_error(m_path, line, token, lineNumber);
1278 else if (line.find(PackageRecord::OutlineRecord::CONTOUR_BEGIN_RECORD_TOKEN) == 0)
1281 if (!(lineStream >> token))
1283 throw_parse_error(m_path, line, token, lineNumber);
1286 if (token != PackageRecord::OutlineRecord::CONTOUR_BEGIN_RECORD_TOKEN)
1288 throw_parse_error(m_path, line, token, lineNumber);
1291 pCurrentContourOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
1292 pCurrentContourOutlineRecord->type = PackageRecord::OutlineRecord::Type::Contour;
1294 else if (line.find(PackageRecord::OutlineRecord::CONTOUR_END_RECORD_TOKEN) == 0)
1297 if (!(lineStream >> token))
1299 throw_parse_error(m_path, line, token, lineNumber);
1302 if (token != PackageRecord::OutlineRecord::CONTOUR_END_RECORD_TOKEN)
1304 throw_parse_error(m_path, line, token, lineNumber);
1307 if (pCurrentPackageRecord !=
nullptr)
1309 if (pCurrentPinRecord !=
nullptr)
1311 pCurrentPinRecord->m_outlineRecords.push_back(pCurrentContourOutlineRecord);
1315 pCurrentPackageRecord->m_outlineRecords.push_back(pCurrentContourOutlineRecord);
1320 throw_parse_error(m_path, line, token, lineNumber);
1323 pCurrentContourOutlineRecord.reset();
1325 else if (line.find(ContourPolygon::BEGIN_RECORD_TOKEN) == 0)
1328 if (!(lineStream >> token))
1330 throw_parse_error(m_path, line, token, lineNumber);
1333 if (token != ContourPolygon::BEGIN_RECORD_TOKEN)
1335 throw_parse_error(m_path, line, token, lineNumber);
1338 pCurrentContourPolygon = std::make_shared<ContourPolygon>();
1340 if (!(lineStream >> pCurrentContourPolygon->xStart))
1342 throw_parse_error(m_path, line, token, lineNumber);
1345 if (!(lineStream >> pCurrentContourPolygon->yStart))
1347 throw_parse_error(m_path, line, token, lineNumber);
1350 if (!(lineStream >> token))
1352 throw_parse_error(m_path, line, token, lineNumber);
1355 if (token == ContourPolygon::ISLAND_TYPE_TOKEN)
1357 pCurrentContourPolygon->type = ContourPolygon::Type::Island;
1359 else if (token == ContourPolygon::HOLE_TYPE_TOKEN)
1361 pCurrentContourPolygon->type = ContourPolygon::Type::Hole;
1365 throw_parse_error(m_path, line, token, lineNumber);
1368 else if (line.find(ContourPolygon::END_RECORD_TOKEN) == 0)
1371 if (!(lineStream >> token))
1373 throw_parse_error(m_path, line, token, lineNumber);
1376 if (token != ContourPolygon::END_RECORD_TOKEN)
1378 throw_parse_error(m_path, line, token, lineNumber);
1381 if (pCurrentContourOutlineRecord !=
nullptr)
1383 pCurrentContourOutlineRecord->m_contourPolygons.push_back(pCurrentContourPolygon);
1384 pCurrentContourPolygon.reset();
1388 throw_parse_error(m_path, line, token, lineNumber);
1391 else if (line.find(ContourPolygon::PolygonPart::ARC_RECORD_TOKEN) == 0)
1394 if (!(lineStream >> token))
1396 throw_parse_error(m_path, line, token, lineNumber);
1399 if (token != ContourPolygon::PolygonPart::ARC_RECORD_TOKEN)
1401 throw_parse_error(m_path, line, token, lineNumber);
1404 auto pPolygonPart = std::make_shared<ContourPolygon::PolygonPart>();
1405 pPolygonPart->type = ContourPolygon::PolygonPart::Type::Arc;
1407 if (!(lineStream >> pPolygonPart->endX))
1409 throw_parse_error(m_path, line, token, lineNumber);
1412 if (!(lineStream >> pPolygonPart->endY))
1414 throw_parse_error(m_path, line, token, lineNumber);
1417 if (!(lineStream >> pPolygonPart->xCenter))
1419 throw_parse_error(m_path, line, token, lineNumber);
1422 if (!(lineStream >> pPolygonPart->yCenter))
1424 throw_parse_error(m_path, line, token, lineNumber);
1427 if (!(lineStream >> token))
1429 throw_parse_error(m_path, line, token, lineNumber);
1432 if (token ==
"y" || token ==
"Y")
1434 pPolygonPart->isClockwise =
true;
1436 else if (token ==
"n" || token ==
"N")
1438 pPolygonPart->isClockwise =
false;
1442 throw_parse_error(m_path, line, token, lineNumber);
1445 if (pCurrentContourPolygon !=
nullptr)
1447 pCurrentContourPolygon->m_polygonParts.push_back(pPolygonPart);
1451 throw_parse_error(m_path, line, token, lineNumber);
1454 else if (line.find(ContourPolygon::PolygonPart::SEGMENT_RECORD_TOKEN) == 0)
1457 if (!(lineStream >> token))
1459 throw_parse_error(m_path, line, token, lineNumber);
1462 if (token != ContourPolygon::PolygonPart::SEGMENT_RECORD_TOKEN)
1464 throw_parse_error(m_path, line, token, lineNumber);
1467 auto pPolygonPart = std::make_shared<ContourPolygon::PolygonPart>();
1468 pPolygonPart->type = ContourPolygon::PolygonPart::Type::Segment;
1470 if (!(lineStream >> pPolygonPart->endX))
1472 throw_parse_error(m_path, line, token, lineNumber);
1475 if (!(lineStream >> pPolygonPart->endY))
1477 throw_parse_error(m_path, line, token, lineNumber);
1480 if (pCurrentContourPolygon !=
nullptr)
1482 pCurrentContourPolygon->m_polygonParts.push_back(pPolygonPart);
1486 throw_parse_error(m_path, line, token, lineNumber);
1492 parse_info pi(m_path, line, lineNumber);
1493 logwarn(pi.toString(
"unrecognized record line in EDADATA file:"));
1505 if (pCurrentNetRecord !=
nullptr)
1509 if (pCurrentSubnetRecord !=
nullptr)
1511 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
1512 pCurrentSubnetRecord.reset();
1515 m_netRecords.push_back(pCurrentNetRecord);
1517 pCurrentNetRecord.reset();
1519 else if (pCurrentPackageRecord !=
nullptr)
1522 if (pCurrentPinRecord !=
nullptr)
1525 if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
1527 throw_parse_error(m_path, line,
"", lineNumber);
1529 pCurrentPinRecord->index =
static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
1530 pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
1531 pCurrentPinRecord.reset();
1535 m_packageRecords.push_back(pCurrentPackageRecord);
1537 pCurrentPackageRecord.reset();
1539 else if (pCurrentFeatureGroupRecord !=
nullptr)
1541 m_featureGroupRecords.push_back(pCurrentFeatureGroupRecord);
1542 pCurrentFeatureGroupRecord.reset();
1545 edaDataFile.close();
1547 catch (parse_error& pe)
1549 auto m = pe.toString(
"Parse Error:");
1552 edaDataFile.close();
1555 catch (std::exception& e)
1557 parse_info pi(m_path, line, lineNumber);
1558 const auto m = pi.toString();
1559 logexception_msg(e, m);
1561 edaDataFile.close();
1569 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord>
1570 EdaDataFile::PackageRecord::to_protobuf()
const
1572 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord> pPackageRecordMessage(
new Odb::Lib::Protobuf::EdaDataFile::PackageRecord);
1573 pPackageRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
1574 pPackageRecordMessage->set_pitch(pitch);
1575 pPackageRecordMessage->set_xmin(xMin);
1576 pPackageRecordMessage->set_ymin(yMin);
1577 pPackageRecordMessage->set_xmax(xMax);
1578 pPackageRecordMessage->set_ymax(yMax);
1580 for (
const auto& pinRecord : m_pinRecords)
1582 auto pPinRecordMessage = pPackageRecordMessage->add_pinrecords();
1583 pPinRecordMessage->CopyFrom(*pinRecord->to_protobuf());
1585 for (
const auto& kvPinRecord : m_pinRecordsByName)
1587 (*pPackageRecordMessage->mutable_pinrecordsbyname())[Odb::Lib::Text::ToUtf8(kvPinRecord.first)] = *kvPinRecord.second->to_protobuf();
1589 for (
const auto& propertyRecord : m_propertyRecords)
1591 auto pPropertyRecordMessage = pPackageRecordMessage->add_propertyrecords();
1592 pPropertyRecordMessage->CopyFrom(*propertyRecord->to_protobuf());
1594 for (
const auto& outlineRecord : m_outlineRecords)
1596 auto pOutlineRecordMessage = pPackageRecordMessage->add_outlinerecords();
1597 pOutlineRecordMessage->CopyFrom(*outlineRecord->to_protobuf());
1599 for (
const auto& kvAttributeAssignment : m_attributeLookupTable)
1601 (*pPackageRecordMessage->mutable_attributelookuptable())[Odb::Lib::Text::ToUtf8(kvAttributeAssignment.first)] =
Odb::Lib::Text::ToUtf8(kvAttributeAssignment.second);
1603 return pPackageRecordMessage;
1606 void EdaDataFile::PackageRecord::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile::PackageRecord& message)
1608 name = message.name();
1609 pitch = message.pitch();
1610 xMin = message.xmin();
1611 yMin = message.ymin();
1612 xMax = message.xmax();
1613 yMax = message.ymax();
1616 for (
const auto& pinRecordMessage : message.pinrecords())
1618 auto pPinRecord = std::make_shared<PinRecord>();
1619 pPinRecord->from_protobuf(pinRecordMessage);
1620 m_pinRecords.push_back(pPinRecord);
1623 for (
const auto& kvPinRecordMessage : message.pinrecordsbyname())
1625 auto pPinRecord = std::make_shared<PinRecord>();
1626 pPinRecord->from_protobuf(kvPinRecordMessage.second);
1627 m_pinRecordsByName[kvPinRecordMessage.first] = pPinRecord;
1630 for (
const auto& propertyRecordMessage : message.propertyrecords())
1632 auto pPropertyRecord = std::make_shared<PropertyRecord>();
1633 pPropertyRecord->from_protobuf(propertyRecordMessage);
1634 m_propertyRecords.push_back(pPropertyRecord);
1637 for (
const auto& outlineRecordMessage : message.outlinerecords())
1639 auto pOutlineRecord = std::make_shared<OutlineRecord>();
1640 pOutlineRecord->from_protobuf(outlineRecordMessage);
1641 m_outlineRecords.push_back(pOutlineRecord);
1644 for (
const auto& kvAttributeAssignment : message.attributelookuptable())
1646 m_attributeLookupTable[kvAttributeAssignment.first] = kvAttributeAssignment.second;
1651 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord> EdaDataFile::PackageRecord::OutlineRecord::to_protobuf()
const
1653 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord> pOutlineRecordMessage(
new Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord);
1654 pOutlineRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord::Type)type);
1655 pOutlineRecordMessage->set_lowerleftx(lowerLeftX);
1656 pOutlineRecordMessage->set_lowerlefty(lowerLeftY);
1657 pOutlineRecordMessage->set_width(width);
1658 pOutlineRecordMessage->set_height(height);
1659 pOutlineRecordMessage->set_xcenter(xCenter);
1660 pOutlineRecordMessage->set_ycenter(yCenter);
1661 pOutlineRecordMessage->set_radius(radius);
1662 pOutlineRecordMessage->set_halfside(halfSide);
1663 for (
const auto& contourPolygon : m_contourPolygons)
1665 auto pContourPolygonMessage = pOutlineRecordMessage->add_contourpolygons();
1666 pContourPolygonMessage->CopyFrom(*contourPolygon->to_protobuf());
1668 return pOutlineRecordMessage;
1671 void EdaDataFile::PackageRecord::OutlineRecord::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord& message)
1673 type = (Type)message.type();
1674 lowerLeftX = message.lowerleftx();
1675 lowerLeftY = message.lowerlefty();
1676 width = message.width();
1677 height = message.height();
1678 xCenter = message.xcenter();
1679 yCenter = message.ycenter();
1680 radius = message.radius();
1681 halfSide = message.halfside();
1682 for (
const auto& contourPolygonMessage : message.contourpolygons())
1684 auto pContourPolygon = std::make_shared<ContourPolygon>();
1685 pContourPolygon->from_protobuf(contourPolygonMessage);
1686 m_contourPolygons.push_back(pContourPolygon);
1691 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord>
1692 EdaDataFile::PackageRecord::PinRecord::to_protobuf()
const
1694 std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord> pPinRecordMessage(
new Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord);
1695 pPinRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
1696 pPinRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord::Type)type);
1697 pPinRecordMessage->set_xcenter(xCenter);
1698 pPinRecordMessage->set_ycenter(yCenter);
1699 pPinRecordMessage->set_finishedholesize(finishedHoleSize);
1700 pPinRecordMessage->set_electricaltype((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord::ElectricalType)electricalType);
1701 pPinRecordMessage->set_mounttype((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord::MountType)mountType);
1702 pPinRecordMessage->set_id(
id);
1703 pPinRecordMessage->set_index(index);
1704 return pPinRecordMessage;
1707 void EdaDataFile::PackageRecord::PinRecord::from_protobuf(
const Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord& message)
1709 name = message.name();
1710 type = (Type)message.type();
1711 xCenter = message.xcenter();
1712 yCenter = message.ycenter();
1713 finishedHoleSize = message.finishedholesize();
1714 electricalType = (ElectricalType)message.electricaltype();
1715 mountType = (MountType)message.mounttype();
1717 index = message.index();
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.