LCOV - code coverage report
Current view: top level - OdbDesignLib/FileModel/Design - EdaDataFile.cpp (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 71.9 % 869 625
Test Date: 2026-11-19 04:56:22 Functions: 73.7 % 38 28
Legend: Lines: hit not hit

            Line data    Source code
       1              : #include "EdaDataFile.h"
       2              : #include <fstream>
       3              : #include <sstream>
       4              : #include "str_utils.h"
       5              : #include "../../enums.h"
       6              : #include "edadatafile.pb.h"
       7              : #include "ArchiveExtractor.h"
       8              : #include "Logger.h"
       9              : #include "../parse_info.h"
      10              : #include "../parse_error.h"
      11              : #include "../invalid_odb_error.h"
      12              : #include "../../Text/Utf8Sanitizer.h"
      13              : 
      14              : using namespace std::filesystem;
      15              : using namespace Utils;
      16              : 
      17              : namespace Odb::Lib::FileModel::Design
      18              : {
      19          105 :     EdaDataFile::EdaDataFile(bool logAllLineParsing)
      20          105 :         : m_logAllLineParsing(logAllLineParsing)
      21              :     {
      22          105 :     }
      23              :    
      24           88 :     EdaDataFile::~EdaDataFile()
      25              :     {
      26           88 :         m_layerNames.clear();
      27           88 :         m_attributeNames.clear();
      28           88 :         m_attributeTextValues.clear();
      29           88 :         m_netRecords.clear();
      30           87 :         m_netRecordsByName.clear();
      31           87 :         m_packageRecords.clear();
      32           87 :         m_packageRecordsByName.clear();
      33           87 :         m_featureGroupRecords.clear();
      34           87 :         m_propertyRecords.clear();
      35           87 :     }
      36              : 
      37            0 :     const std::filesystem::path& EdaDataFile::GetPath() const
      38              :     {
      39            0 :         return m_path;
      40              :     }
      41              : 
      42            0 :     const std::filesystem::path& EdaDataFile::GetDirectory() const
      43              :     {
      44            0 :         return m_directory;
      45              :     }
      46              : 
      47            0 :     const std::string& EdaDataFile::GetUnits() const
      48              :     {
      49            0 :         return m_units;
      50              :     }
      51              : 
      52            0 :     const std::string& EdaDataFile::GetSource() const
      53              :     {
      54            0 :         return m_source;
      55              :     }
      56              : 
      57       859035 :     EdaDataFile::NetRecord::SubnetRecord::~SubnetRecord()
      58              :     {
      59       859035 :         m_featureIdRecords.clear();
      60       859034 :     }
      61              : 
      62       886191 :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord> EdaDataFile::NetRecord::SubnetRecord::to_protobuf() const
      63              :     {
      64       886191 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord> pSubnetRecordMessage(new Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord);       
      65       886191 :         pSubnetRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord::Type) type);
      66       886191 :         if (type == Type::Toeprint)
      67              :         {
      68       249249 :             pSubnetRecordMessage->set_componentnumber(componentNumber);
      69       249249 :             pSubnetRecordMessage->set_toeprintnumber(toeprintNumber);
      70       249249 :             pSubnetRecordMessage->set_side((Odb::Lib::Protobuf::BoardSide)side);
      71              :         }
      72       636942 :         else if (type == Type::Plane)
      73              :         {
      74         9455 :             pSubnetRecordMessage->set_filltype((Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord::FillType)fillType);
      75         9455 :             pSubnetRecordMessage->set_cutouttype((Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord::CutoutType) cutoutType);
      76         9455 :             pSubnetRecordMessage->set_fillsize(fillSize);
      77              :         }
      78              : 
      79      6001560 :         for (const auto& featureIdRecord : m_featureIdRecords)
      80              :         {
      81      5115369 :             auto pFeatureIdRecordMessage = pSubnetRecordMessage->add_featureidrecords();
      82      5115369 :             pFeatureIdRecordMessage->CopyFrom(*featureIdRecord->to_protobuf());
      83              :         }
      84       886191 :         return pSubnetRecordMessage;
      85            0 :     }
      86              : 
      87        52389 :     void EdaDataFile::NetRecord::SubnetRecord::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::NetRecord::SubnetRecord& message)
      88              :     {
      89        52389 :                 type = static_cast<Type>(message.type());
      90              :        
      91        52389 :                 if (type == Type::Toeprint)
      92              :                 {
      93        13327 :                         componentNumber = message.componentnumber();
      94        13327 :                         toeprintNumber = message.toeprintnumber();
      95        13327 :                         side = static_cast<BoardSide>(message.side());
      96              :                 }
      97        39062 :                 else if (type == Type::Plane)
      98              :                 {
      99          841 :                         fillType = static_cast<FillType>(message.filltype());
     100          841 :                         cutoutType = static_cast<CutoutType>(message.cutouttype());
     101          841 :                         fillSize = message.fillsize();
     102          841 :             index = message.index();
     103              :                 }
     104              : 
     105       356432 :         for (const auto& featureIdRecordMessage : message.featureidrecords())
     106              :         {
     107       304043 :             auto pFeatureIdRecord = std::make_shared<FeatureIdRecord>();
     108       304043 :             pFeatureIdRecord->from_protobuf(featureIdRecordMessage);
     109       304043 :             m_featureIdRecords.push_back(pFeatureIdRecord);
     110       304043 :         }
     111        52389 :     }
     112              : 
     113        55000 :     EdaDataFile::NetRecord::~NetRecord()
     114              :     {
     115        55000 :         m_subnetRecords.clear();
     116        54999 :         m_propertyRecords.clear();
     117        54999 :     }
     118              : 
     119        59200 :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord> EdaDataFile::NetRecord::to_protobuf() const
     120              :     {
     121        59200 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::NetRecord> pNetRecordMessage(new Odb::Lib::Protobuf::EdaDataFile::NetRecord);
     122       118400 :         pNetRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
     123              :         //pNetRecordMessage->set_attributesidstring(attributesIdString);
     124        59200 :         pNetRecordMessage->set_index(index);
     125        59200 :         if (id.has_value())
     126              :         {
     127            2 :             pNetRecordMessage->set_id(*id);
     128              :         }
     129              : 
     130        59200 :         for (const auto& propertyRecord : m_propertyRecords)
     131              :         {
     132            0 :             auto pPropertyRecordMessage = pNetRecordMessage->add_propertyrecords();
     133            0 :             pPropertyRecordMessage->CopyFrom(*propertyRecord->to_protobuf());
     134              :         }
     135              : 
     136       945391 :         for (const auto& subnetRecord : m_subnetRecords)
     137              :         {
     138       886191 :                         auto pSubnetRecordMessage = pNetRecordMessage->add_subnetrecords();
     139       886191 :                         pSubnetRecordMessage->CopyFrom(*subnetRecord->to_protobuf());
     140              :         }
     141       118398 :         for (const auto& kvAttributeAssignment : m_attributeLookupTable)
     142              :         {
     143        59198 :             (*pNetRecordMessage->mutable_attributelookuptable())[Odb::Lib::Text::ToUtf8(kvAttributeAssignment.first)] = Odb::Lib::Text::ToUtf8(kvAttributeAssignment.second);
     144              :         }
     145        59200 :         return pNetRecordMessage;
     146            0 :     }
     147              : 
     148         3288 :     void EdaDataFile::NetRecord::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::NetRecord& message)
     149              :     {
     150         3288 :         name = message.name();
     151              :                 //attributesIdString = message.attributesidstring();
     152         3288 :                 index = message.index();
     153         3288 :                 if (message.has_id())
     154              :                 {
     155            2 :                         id = message.id();
     156              :                 }
     157              : 
     158         3288 :                 for (const auto& propertyRecordMessage : message.propertyrecords())
     159              :                 {
     160            0 :                         auto pPropertyRecord = std::make_shared<PropertyRecord>();
     161            0 :                         pPropertyRecord->from_protobuf(propertyRecordMessage);
     162            0 :                         m_propertyRecords.push_back(pPropertyRecord);
     163            0 :                 }
     164              : 
     165        55677 :                 for (const auto& subnetRecordMessage : message.subnetrecords())
     166              :                 {
     167        52389 :                         auto pSubnetRecord = std::make_shared<SubnetRecord>();
     168        52389 :                         pSubnetRecord->from_protobuf(subnetRecordMessage);
     169        52389 :                         m_subnetRecords.push_back(pSubnetRecord);
     170        52389 :                 }   
     171              : 
     172         9860 :         for (const auto& kvAttributeAssignment : message.attributelookuptable())
     173              :         {
     174         3286 :             m_attributeLookupTable[kvAttributeAssignment.first] = kvAttributeAssignment.second;
     175              :         }
     176         3288 :     }
     177              : 
     178              :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord>
     179      5115370 :     EdaDataFile::FeatureIdRecord::to_protobuf() const
     180              :     {
     181      5115370 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord> pFeatureIdRecordMessage(new Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord);        
     182      5115370 :         pFeatureIdRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord::Type) type);
     183      5115370 :         pFeatureIdRecordMessage->set_layernumber(layerNumber);
     184      5115370 :         pFeatureIdRecordMessage->set_featurenumber(featureNumber);
     185      5115370 :         return pFeatureIdRecordMessage;
     186            0 :     }
     187              : 
     188       304044 :     void EdaDataFile::FeatureIdRecord::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord& message)
     189              :     {
     190       304044 :         type = static_cast<Type>(message.type());
     191       304044 :         layerNumber = message.layernumber();
     192       304044 :         featureNumber = message.featurenumber();
     193       304044 :     }   
     194              : 
     195              :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord>
     196            1 :     EdaDataFile::FeatureGroupRecord::to_protobuf() const
     197              :     {
     198            1 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord> pFeatureGroupRecordMessage(new Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord);
     199            2 :         pFeatureGroupRecordMessage->set_type(Odb::Lib::Text::ToUtf8(type));
     200            2 :         for (const auto& featureIdRecord : m_featureIdRecords)
     201              :         {
     202            1 :             auto pFeatureIdRecordMessage = pFeatureGroupRecordMessage->add_featureidrecords();
     203            1 :             pFeatureIdRecordMessage->CopyFrom(*featureIdRecord->to_protobuf());
     204              :         }
     205            2 :         for (const auto& propertyRecord : m_propertyRecords)
     206              :         {
     207              :             // PropertyRecord payloads belong in propertyrecords (field 2); the
     208              :             // previous add_featureidrecords() here was a cross-type
     209              :             // Message::CopyFrom (type confusion / UB) whenever a design carries
     210              :             // feature-group property records.
     211            1 :             auto pPropertyRecordMessage = pFeatureGroupRecordMessage->add_propertyrecords();
     212            1 :             pPropertyRecordMessage->CopyFrom(*propertyRecord->to_protobuf());
     213              :         }
     214            1 :         return pFeatureGroupRecordMessage;
     215            0 :     }
     216              : 
     217            1 :     void EdaDataFile::FeatureGroupRecord::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::FeatureGroupRecord& message)
     218              :     {
     219            1 :         type = message.type();
     220            2 :         for (const auto& featureIdRecordMessage : message.featureidrecords())
     221              :                 {
     222            1 :                         auto pFeatureIdRecord = std::make_shared<FeatureIdRecord>();
     223            1 :                         pFeatureIdRecord->from_protobuf(featureIdRecordMessage);
     224            1 :                         m_featureIdRecords.push_back(pFeatureIdRecord);
     225            1 :                 }
     226            2 :         for (const auto& propertyRecordMessage : message.propertyrecords())
     227              :         {
     228            1 :             auto pPropertyRecord = std::make_shared<PropertyRecord>();
     229            1 :                         pPropertyRecord->from_protobuf(propertyRecordMessage);
     230            1 :                         m_propertyRecords.push_back(pPropertyRecord);
     231            1 :                 }
     232            1 :     }    
     233              : 
     234           82 :     const std::vector<std::string>& EdaDataFile::GetLayerNames() const
     235              :     {
     236           82 :         return m_layerNames;
     237              :     }
     238              : 
     239           82 :     const std::vector<std::string>& EdaDataFile::GetAttributeNames() const
     240              :     {
     241           82 :         return m_attributeNames;
     242              :     }
     243              : 
     244           82 :     const std::vector<std::string>& EdaDataFile::GetAttributeTextValues() const
     245              :     {
     246           82 :         return m_attributeTextValues;
     247              :     }
     248              : 
     249          224 :     const EdaDataFile::NetRecord::Vector& EdaDataFile::GetNetRecords() const
     250              :     {
     251          224 :         return m_netRecords;
     252              :     }
     253              : 
     254            0 :     const EdaDataFile::NetRecord::StringMap& EdaDataFile::GetNetRecordsByName() const
     255              :     {
     256            0 :         return m_netRecordsByName;
     257              :     }
     258              : 
     259          224 :     const EdaDataFile::PackageRecord::Vector& EdaDataFile::GetPackageRecords() const
     260              :     {
     261          224 :         return m_packageRecords;
     262              :     }
     263              : 
     264            0 :     const EdaDataFile::PackageRecord::StringMap& EdaDataFile::GetPackageRecordsByName() const
     265              :     {
     266            0 :         return m_packageRecordsByName;
     267              :     }
     268              : 
     269           82 :     const EdaDataFile::FeatureGroupRecord::Vector& EdaDataFile::GetFeatureGroupRecords() const
     270              :     {
     271           82 :         return m_featureGroupRecords;
     272              :     }
     273              : 
     274           82 :     const PropertyRecord::Vector& EdaDataFile::GetPropertyRecords() const
     275              :     {
     276           82 :         return m_propertyRecords;
     277              :     }
     278              : 
     279           97 :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile> EdaDataFile::to_protobuf() const
     280              :     {
     281           97 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile> pEdaDataFileMessage(new Odb::Lib::Protobuf::EdaDataFile);
     282          194 :         pEdaDataFileMessage->set_path(Odb::Lib::Text::ToUtf8(m_path.string()));
     283          194 :         pEdaDataFileMessage->set_units(Odb::Lib::Text::ToUtf8(m_units));
     284          194 :         pEdaDataFileMessage->set_source(Odb::Lib::Text::ToUtf8(m_source));
     285         1640 :         for (const auto& layerName : m_layerNames)
     286              :         {
     287         1543 :                         pEdaDataFileMessage->add_layernames(Odb::Lib::Text::ToUtf8(layerName));
     288              :                 }
     289          187 :         for (const auto& attributeName : m_attributeNames)
     290              :         {
     291           90 :             pEdaDataFileMessage->add_attributenames(Odb::Lib::Text::ToUtf8(attributeName));
     292              :         }
     293           97 :         for (const auto& attrTextValue : m_attributeTextValues)
     294              :         {
     295            0 :             pEdaDataFileMessage->add_attributetextvalues(Odb::Lib::Text::ToUtf8(attrTextValue));
     296              :         }
     297        59295 :         for (const auto& pNetRecord : m_netRecords)
     298              :         {
     299        59198 :             auto pNetRecordMessage = pEdaDataFileMessage->add_netrecords();
     300        59198 :             pNetRecordMessage->CopyFrom(*pNetRecord->to_protobuf());
     301              :         }
     302           97 :         for (const auto& kvNetRecord : m_netRecordsByName)
     303              :         {
     304            0 :             (*pEdaDataFileMessage->mutable_netrecordsbyname())[Odb::Lib::Text::ToUtf8(kvNetRecord.first)] = *kvNetRecord.second->to_protobuf();
     305              :         }
     306         8628 :         for (const auto& pPackageRecord : m_packageRecords)
     307              :         {
     308         8531 :             auto pPackageRecordMessage = pEdaDataFileMessage->add_packagerecords();
     309         8531 :             pPackageRecordMessage->CopyFrom(*pPackageRecord->to_protobuf());
     310              :         }
     311           97 :         for (const auto& kvPackageRecord : m_packageRecordsByName)
     312              :         {
     313            0 :             (*pEdaDataFileMessage->mutable_packagerecordsbyname())[Odb::Lib::Text::ToUtf8(kvPackageRecord.first)] = *kvPackageRecord.second->to_protobuf();
     314              :         }
     315           97 :         for (const auto& pPropertyRecord : m_propertyRecords)
     316              :         {
     317            0 :             auto pPropertyRecordMessage = pEdaDataFileMessage->add_propertyrecords();
     318            0 :             pPropertyRecordMessage->CopyFrom(*pPropertyRecord->to_protobuf());
     319              :         }
     320           97 :         for (const auto& pFeatureGroupRecord : m_featureGroupRecords)
     321              :         {
     322            0 :             auto pFeatureGroupRecordMessage = pEdaDataFileMessage->add_featuregrouprecords();
     323            0 :             pFeatureGroupRecordMessage->CopyFrom(*pFeatureGroupRecord->to_protobuf());
     324              :         }
     325              : 
     326           97 :         return pEdaDataFileMessage;
     327            0 :     }
     328              : 
     329            8 :     void EdaDataFile::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile& message)
     330              :     {
     331            8 :         m_path = message.path();
     332            8 :                 m_units = message.units();
     333            8 :                 m_source = message.source();
     334          113 :                 for (const auto& layerName : message.layernames())
     335              :                 {
     336          105 :                         m_layerNames.push_back(layerName);
     337              :                 }
     338           18 :                 for (const auto& attributeName : message.attributenames())
     339              :                 {
     340           10 :                         m_attributeNames.push_back(attributeName);
     341              :                 }
     342            8 :                 for (const auto& attrTextValue : message.attributetextvalues())
     343              :                 {
     344            0 :                         m_attributeTextValues.push_back(attrTextValue);
     345              :                 }
     346         3294 :                 for (const auto& netRecordMessage : message.netrecords())
     347              :                 {
     348         3286 :                         auto pNetRecord = std::make_shared<NetRecord>();
     349         3286 :                         pNetRecord->from_protobuf(netRecordMessage);
     350         3286 :                         m_netRecords.push_back(pNetRecord);
     351         3286 :                 }
     352            8 :                 for (const auto& kvNetRecordMessage : message.netrecordsbyname())
     353              :                 {
     354            0 :                         auto pNetRecord = std::make_shared<NetRecord>();
     355            0 :                         pNetRecord->from_protobuf(kvNetRecordMessage.second);
     356            0 :                         m_netRecordsByName[kvNetRecordMessage.first] = pNetRecord;
     357            0 :                 }
     358          593 :                 for (const auto& packageRecordMessage : message.packagerecords())
     359              :                 {
     360          585 :                         auto pPackageRecord = std::make_shared<PackageRecord>();
     361          585 :                         pPackageRecord->from_protobuf(packageRecordMessage);
     362          585 :                         m_packageRecords.push_back(pPackageRecord);
     363          585 :                 }
     364            8 :                 for (const auto& kvPackageRecordMessage : message.packagerecordsbyname())
     365              :                 {
     366            0 :                         auto pPackageRecord = std::make_shared<PackageRecord>();
     367            0 :                         pPackageRecord->from_protobuf(kvPackageRecordMessage.second);
     368            0 :                         m_packageRecordsByName[kvPackageRecordMessage.first] = pPackageRecord;
     369            0 :                 }
     370            8 :                 for (const auto& propertyRecordMessage : message.propertyrecords())
     371              :                 {
     372            0 :                         auto pPropertyRecord = std::make_shared<PropertyRecord>();
     373            0 :                         pPropertyRecord->from_protobuf(propertyRecordMessage);
     374            0 :                         m_propertyRecords.push_back(pPropertyRecord);
     375            0 :                 }
     376            8 :                 for (const auto& featureGroupRecordMessage : message.featuregrouprecords())
     377              :                 {
     378            0 :                         auto pFeatureGroupRecord = std::make_shared<FeatureGroupRecord>();
     379            0 :                         pFeatureGroupRecord->from_protobuf(featureGroupRecordMessage);
     380            0 :                         m_featureGroupRecords.push_back(pFeatureGroupRecord);
     381            0 :                 }       
     382            8 :     }
     383              : 
     384            0 :     bool EdaDataFile::Save(std::ostream& os)
     385              :     {
     386            0 :         return true;
     387              :     }
     388              : 
     389           97 :     bool EdaDataFile::Parse(std::filesystem::path path)
     390              :     {
     391           97 :         std::ifstream edaDataFile;
     392           97 :         int lineNumber = 0;
     393           97 :         std::string line;
     394              : 
     395              :         try
     396              :         {
     397          388 :             loginfo("checking for extraction...");
     398              : 
     399           97 :             m_directory = path;
     400           97 :             m_path = ArchiveExtractor::getUncompressedFilePath(m_directory.string(), EDADATA_FILENAME);
     401              : 
     402           97 :             if (!std::filesystem::exists(m_path))
     403              :             {
     404            0 :                 auto message = "eda/data file does not exist: [" + m_path.string() + "]";
     405            0 :                 throw invalid_odb_error(message.c_str());
     406            0 :             }
     407           97 :             else if (!std::filesystem::is_regular_file(m_path))
     408              :             {
     409            0 :                 auto message = "eda/data is not a file: [" + m_path.string() + "]";
     410            0 :                 throw invalid_odb_error(message.c_str());
     411            0 :             }
     412              : 
     413          388 :             loginfo("any extraction complete, parsing data...");
     414              :             
     415           97 :             edaDataFile.open(m_path.string(), std::ios::in);
     416           97 :             if (!edaDataFile.is_open())
     417              :             {
     418            0 :                 auto message = "unable to open eda/data file: [" + m_path.string() + "]";
     419            0 :                 throw invalid_odb_error(message.c_str());
     420            0 :             }
     421              : 
     422           97 :             std::shared_ptr<NetRecord> pCurrentNetRecord;
     423           97 :             std::shared_ptr<NetRecord::SubnetRecord> pCurrentSubnetRecord;
     424              : 
     425           97 :             std::shared_ptr<PackageRecord> pCurrentPackageRecord;
     426           97 :             std::shared_ptr<PackageRecord::PinRecord> pCurrentPinRecord;
     427              : 
     428           97 :             std::shared_ptr<PackageRecord::OutlineRecord> pCurrentContourOutlineRecord;
     429           97 :             std::shared_ptr<ContourPolygon> pCurrentContourPolygon;
     430              : 
     431           97 :             FeatureGroupRecord::shared_ptr pCurrentFeatureGroupRecord;
     432              : 
     433      7518611 :             while (std::getline(edaDataFile, line))
     434              :             {
     435              :                 // keep track of line number
     436      7518517 :                 lineNumber++;
     437              : 
     438              :                 // trim whitespace from beginning and end of line
     439      7518517 :                 Utils::str_trim(line);
     440      7518517 :                 if (!line.empty())
     441              :                 {
     442      7518517 :                     if (m_logAllLineParsing)
     443              :                     {
     444            0 :                         parse_info pi(m_path, line, lineNumber);
     445            0 :                         logdebug(pi.toString("Parsing line..."));
     446            0 :                     }
     447              : 
     448      7518517 :                     std::stringstream lineStream(line);
     449              :                    
     450     15037034 :                     if (line.find(ATTRIBUTE_NAME_TOKEN) == 0 ||
     451     30074068 :                         line.find(std::string(COMMENT_TOKEN) + ATTRIBUTE_NAME_TOKEN) == 0)  // backward compatibility dictates allowing comment character in front of attribute value token
     452              :                     {
     453              :                         // component attribute name line        
     454          185 :                         std::string token;
     455              :                         // TODO: continue on failing line parse, to make a less strict/more robust parser (make a flag: enum ParseStrictness { strict, lax })
     456          185 :                         if (!std::getline(lineStream, token, ' '))
     457              :                         {
     458            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     459              :                         }
     460          185 :                         else if (!std::getline(lineStream, token, ' '))
     461              :                         {
     462            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     463              :                         }
     464          185 :                         m_attributeNames.push_back(token);
     465          185 :                     }
     466     15036664 :                     else if (line.find(ATTRIBUTE_VALUE_TOKEN) == 0 ||
     467     30073328 :                         line.find(std::string(COMMENT_TOKEN) + ATTRIBUTE_VALUE_TOKEN) == 0) // backward compatibility dictates allowing comment character in front of attribute value token
     468              :                     {
     469              :                         // component attribute text string values       
     470            0 :                         std::string token;
     471            0 :                         if (!std::getline(lineStream, token, ' '))
     472              :                         {
     473            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     474              :                         }
     475            0 :                         else if (!std::getline(lineStream, token, ' '))
     476              :                         {
     477            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     478              :                         }
     479            0 :                         m_attributeTextValues.push_back(token);
     480            0 :                     }
     481      7518332 :                     else if (line.find(COMMENT_TOKEN) == 0)
     482              :                     {
     483              :                         // comment line
     484              :                         // TODO: attribute lines can begin with a comment for backward compatbility
     485              :                     }
     486      7406848 :                     else if (line.find(UNITS_TOKEN) == 0)
     487              :                     {
     488              :                         // units line
     489           97 :                         std::string token;
     490           97 :                         if (!std::getline(lineStream, token, '='))
     491              :                         {
     492            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     493              :                         }
     494           97 :                         else if (!std::getline(lineStream, token, '='))
     495              :                         {
     496            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     497              :                         }
     498           97 :                         m_units = token;
     499           97 :                     }
     500      7406751 :                     else if (line.find(HEADER_RECORD_TOKEN) == 0)
     501              :                     {
     502              :                         // component record line
     503           97 :                         std::string token;
     504              : 
     505           97 :                         lineStream >> token;
     506           97 :                         if (token != HEADER_RECORD_TOKEN)
     507              :                         {
     508            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     509              :                         }
     510              : 
     511              :                         // read the rest of the line as the source
     512           97 :                         if (!std::getline(lineStream, m_source))
     513              :                         {
     514            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     515              :                         }
     516              : 
     517           97 :                         Utils::str_trim(m_source);
     518           97 :                     }
     519      7406654 :                     else if (line.find(LAYER_NAMES_RECORD_TOKEN) == 0)
     520              :                     {
     521              :                         // component record line
     522           97 :                         std::string token;
     523              : 
     524           97 :                         lineStream >> token;
     525           97 :                         if (token != LAYER_NAMES_RECORD_TOKEN)
     526              :                         {
     527            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     528              :                         }
     529              : 
     530         2098 :                         while (lineStream >> token)
     531              :                         {
     532         2001 :                             m_layerNames.push_back(token);
     533              :                         }
     534           97 :                     }
     535      7406557 :                     else if (line.find(PropertyRecord::RECORD_TOKEN) == 0)
     536              :                     {
     537              :                         // component property record line
     538        11280 :                         std::string token;
     539        11280 :                         if (!(lineStream >> token))
     540              :                         {
     541            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     542              :                         }
     543              : 
     544        11280 :                         if (token != PropertyRecord::RECORD_TOKEN)
     545              :                         {
     546            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     547              :                         }
     548              : 
     549        11280 :                         auto pPropertyRecord = std::make_shared<PropertyRecord>();
     550              : 
     551        11280 :                         if (!(lineStream >> pPropertyRecord->name))
     552              :                         {
     553            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     554              :                         }
     555              : 
     556        11280 :                         if (!(lineStream >> token))
     557              :                         {
     558            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     559              :                         }
     560              : 
     561        11280 :                         if (!token.empty())
     562              :                         {
     563              :                             // handle case where the beginning of the value, after the opening single-quote, is whitespace...
     564        11280 :                             if (token == "'")
     565              :                             {
     566              :                                 // eat the single-quote and get the next token, i.e. the actual value (w/ space in front)
     567            0 :                                 if (!(lineStream >> token))
     568              :                                 {
     569            0 :                                     throw_parse_error(m_path, line, token, lineNumber);
     570              :                                 }
     571              :                             }
     572              : 
     573        11280 :                             if (token.size() > 0 && token[0] == '\'')
     574              :                             {
     575              :                                 // remove leading quote                                                 
     576        11280 :                                 token.erase(0, 1);
     577              :                             }
     578              : 
     579        11280 :                             if (token.size() > 0 && token[token.size() - 1] == '\'')
     580              :                             {
     581              :                                 // remove trailing quote
     582        11280 :                                 token.erase(token.size() - 1);
     583              :                             }
     584              : 
     585        11280 :                             Utils::str_trim(token);
     586              :                         }
     587              : 
     588        11280 :                         pPropertyRecord->value = token;
     589              : 
     590              :                         double f;
     591        11280 :                         while (lineStream >> f)
     592              :                         {
     593            0 :                             pPropertyRecord->floatValues.push_back(f);
     594              :                         }
     595              : 
     596        11280 :                         if (pCurrentNetRecord != nullptr)
     597              :                         {
     598            0 :                             pCurrentNetRecord->m_propertyRecords.push_back(pPropertyRecord);
     599              :                         }
     600        11280 :                         else if (pCurrentPackageRecord != nullptr)
     601              :                         {
     602        11280 :                             pCurrentPackageRecord->m_propertyRecords.push_back(pPropertyRecord);
     603              :                         }
     604            0 :                         else if (pCurrentFeatureGroupRecord != nullptr)
     605              :                         {
     606            0 :                             pCurrentFeatureGroupRecord->m_propertyRecords.push_back(pPropertyRecord);
     607              :                         }
     608              :                         else
     609              :                         {
     610              :                             // top-level PRP record
     611            0 :                             m_propertyRecords.push_back(pPropertyRecord);
     612              :                         }                        
     613        11280 :                     }
     614      7395277 :                     else if (line.find(NET_RECORD_TOKEN) == 0)
     615              :                     {
     616              :                         // net record line
     617        63689 :                         std::string token;
     618              : 
     619        63689 :                         if (!(lineStream >> token))
     620              :                         {
     621            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     622              :                         }
     623              : 
     624        63689 :                         if (token != NET_RECORD_TOKEN)
     625              :                         {
     626            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     627              :                         }
     628              : 
     629              :                         // finish current (previous) net record
     630        63689 :                         if (pCurrentNetRecord != nullptr)
     631              :                         {
     632              :                             // finish up (any) current subnet record
     633        63592 :                             if (pCurrentSubnetRecord != nullptr)
     634              :                             {
     635        63592 :                                 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
     636        63592 :                                 pCurrentSubnetRecord.reset();
     637              :                             }
     638              : 
     639        63592 :                             m_netRecords.push_back(pCurrentNetRecord);                            
     640              :                             //m_netRecordsByName[pCurrentNetRecord->name] = pCurrentNetRecord;
     641        63592 :                             pCurrentNetRecord.reset();
     642              :                         }
     643              : 
     644              :                         // net name
     645        63689 :                         if (!std::getline(lineStream, token, ';'))
     646              :                         {
     647            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     648              :                         }
     649              : 
     650              :                         // trim whitespace from beginning                        
     651        63689 :                         str_trim(token);
     652              : 
     653              :                         // create new net record
     654        63689 :                         pCurrentNetRecord = std::make_shared<NetRecord>();
     655        63689 :                         pCurrentNetRecord->name = token;
     656        63689 :                         pCurrentNetRecord->index = static_cast<unsigned>(m_netRecords.size());
     657              : 
     658        63689 :                         std::string attrIdString;
     659        63689 :                         lineStream >> attrIdString;
     660        63689 :                         if (!pCurrentNetRecord->ParseAttributeLookupTable(attrIdString, pCurrentNetRecord->id))
     661              :                         {
     662            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     663              :                         }
     664        63689 :                     }
     665      7331588 :                     else if (line.find(NetRecord::SubnetRecord::RECORD_TOKEN) == 0)
     666              :                     {
     667              :                         // component record line
     668      1009764 :                         std::string token;
     669              : 
     670      1009764 :                         lineStream >> token;
     671      1009764 :                         if (token != NetRecord::SubnetRecord::RECORD_TOKEN)
     672              :                         {
     673            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     674              :                         }
     675              : 
     676      1009764 :                         if (pCurrentNetRecord != nullptr)
     677              :                         {
     678              :                             // finish current (previous) subnet record
     679      1009764 :                             if (pCurrentSubnetRecord != nullptr)
     680              :                             {
     681       946075 :                                 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
     682       946075 :                                 pCurrentSubnetRecord.reset();
     683              :                             }
     684              :                         }
     685              : 
     686      1009764 :                         pCurrentSubnetRecord = std::make_shared<NetRecord::SubnetRecord>();
     687      1009764 :                         pCurrentSubnetRecord->index = static_cast<unsigned>(pCurrentNetRecord->m_subnetRecords.size());
     688              : 
     689              :                         // subnet type
     690      1009764 :                         lineStream >> token;
     691      1009764 :                         if (token == NetRecord::SubnetRecord::RECORD_TYPE_VIA_TOKEN)
     692              :                         {
     693       591178 :                             pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Via;
     694              :                         }
     695       418586 :                         else if (token == NetRecord::SubnetRecord::RECORD_TYPE_TRACE_TOKEN)
     696              :                         {
     697       143644 :                             pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Trace;
     698              :                         }
     699       274942 :                         else if (token == NetRecord::SubnetRecord::RECORD_TYPE_PLANE_TOKEN)
     700              :                         {
     701        15743 :                             pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Plane;
     702              : 
     703              :                             // fill type
     704        15743 :                             lineStream >> token;
     705        15743 :                             if (token == "S")
     706              :                             {
     707        15743 :                                 pCurrentSubnetRecord->fillType = NetRecord::SubnetRecord::FillType::Solid;
     708              :                             }
     709            0 :                             else if (token == "O")
     710              :                             {
     711            0 :                                 pCurrentSubnetRecord->fillType = NetRecord::SubnetRecord::FillType::Outline;
     712              :                             }
     713              :                             else
     714              :                             {
     715            0 :                                 throw_parse_error(m_path, line, token, lineNumber);
     716              :                             }
     717              : 
     718              :                             // cutout type
     719        15743 :                             lineStream >> token;
     720        15743 :                             if (token == "C")
     721              :                             {
     722        15743 :                                 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Circle;
     723              :                             }
     724            0 :                             else if (token == "R")
     725              :                             {
     726            0 :                                 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Rectangle;
     727              :                             }
     728            0 :                             else if (token == "O")
     729              :                             {
     730            0 :                                 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Octagon;
     731              :                             }
     732            0 :                             else if (token == "E")
     733              :                             {
     734            0 :                                 pCurrentSubnetRecord->cutoutType = NetRecord::SubnetRecord::CutoutType::Exact;
     735              :                             }
     736              :                             else
     737              :                             {
     738            0 :                                 throw_parse_error(m_path, line, token, lineNumber);
     739              :                             }
     740              : 
     741              :                             // fill size
     742        15743 :                             lineStream >> pCurrentSubnetRecord->fillSize;
     743              :                         }
     744       259199 :                         else if (token == NetRecord::SubnetRecord::RECORD_TYPE_TOEPRINT_TOKEN)
     745              :                         {
     746       259199 :                             pCurrentSubnetRecord->type = NetRecord::SubnetRecord::Type::Toeprint;
     747              : 
     748              :                             // side
     749       259199 :                             lineStream >> token;
     750       259199 :                             if (token == "T")
     751              :                             {
     752       198251 :                                 pCurrentSubnetRecord->side = BoardSide::Top;
     753              :                             }
     754        60948 :                             else if (token == "B")
     755              :                             {
     756        60948 :                                 pCurrentSubnetRecord->side = BoardSide::Bottom;
     757              :                             }
     758              :                             else
     759              :                             {
     760            0 :                                 throw_parse_error(m_path, line, token, lineNumber);
     761              :                             }
     762              : 
     763              :                             // componentNumber
     764       259199 :                             lineStream >> pCurrentSubnetRecord->componentNumber;
     765              : 
     766              :                             // toeprintNumber
     767       259199 :                             lineStream >> pCurrentSubnetRecord->toeprintNumber;
     768              :                         }
     769              :                         else
     770              :                         {
     771            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     772              :                         }
     773      1009764 :                     }
     774      6321824 :                     else if (line.find(FEATURE_ID_RECORD_TOKEN) == 0)
     775              :                     {
     776              :                         // component record line
     777      5857522 :                         std::string token;
     778              : 
     779      5857522 :                         if (!(lineStream >> token) || token != FEATURE_ID_RECORD_TOKEN)
     780              :                         {
     781            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     782              :                         }
     783              : 
     784      5857522 :                         auto pFeatureIdRecord = std::make_shared<FeatureIdRecord>();
     785              : 
     786              :                         // type
     787      5857522 :                         if (!(lineStream >> token))
     788              :                         {
     789            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     790              :                         }
     791              : 
     792      5857522 :                         if (token == "C")
     793              :                         {
     794      5021789 :                             pFeatureIdRecord->type = FeatureIdRecord::Type::Copper;
     795              :                         }
     796       835733 :                         else if (token == "L")
     797              :                         {
     798       370020 :                             pFeatureIdRecord->type = FeatureIdRecord::Type::Laminate;
     799              :                         }
     800       465713 :                         else if (token == "H")
     801              :                         {
     802       465713 :                             pFeatureIdRecord->type = FeatureIdRecord::Type::Hole;
     803              :                         }
     804              :                         else
     805              :                         {
     806            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     807              :                         }
     808              : 
     809              :                         // layer number
     810      5857522 :                         if (!(lineStream >> pFeatureIdRecord->layerNumber))
     811              :                         {
     812            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     813              :                         }
     814              : 
     815              :                         // feature number
     816      5857522 :                         if (!(lineStream >> pFeatureIdRecord->featureNumber))
     817              :                         {
     818            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     819              :                         }
     820              : 
     821     11715044 :                         if (pCurrentNetRecord != nullptr &&
     822      5857522 :                             pCurrentSubnetRecord != nullptr)
     823              :                         {
     824      5857522 :                             pCurrentSubnetRecord->m_featureIdRecords.push_back(pFeatureIdRecord);
     825              :                         }
     826            0 :                         else if (pCurrentFeatureGroupRecord != nullptr)
     827              :                         {
     828            0 :                             pCurrentFeatureGroupRecord->m_featureIdRecords.push_back(pFeatureIdRecord);
     829              :                         }
     830              :                         else
     831              :                         {
     832            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     833              :                         }
     834      5857522 :                     }
     835       464302 :                     else if (line.find(PACKAGE_RECORD_TOKEN) == 0)
     836              :                     {
     837              :                         // package record line
     838        11142 :                         std::string token;
     839              : 
     840        11142 :                         if (!(lineStream >> token) || token != PACKAGE_RECORD_TOKEN)
     841              :                         {
     842            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     843              :                         }
     844              : 
     845              :                         // finish current (previous) net record
     846        11142 :                         if (pCurrentNetRecord != nullptr)
     847              :                         {
     848              :                             // finish up (any) current subnet record
     849           97 :                             if (pCurrentSubnetRecord != nullptr)
     850              :                             {
     851           97 :                                 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
     852           97 :                                 pCurrentSubnetRecord.reset();
     853              :                             }
     854              : 
     855           97 :                             m_netRecords.push_back(pCurrentNetRecord);
     856              :                             //m_netRecordsByName[pCurrentNetRecord->name] = pCurrentNetRecord;
     857           97 :                             pCurrentNetRecord.reset();
     858              :                         }
     859        11045 :                         else if (pCurrentPackageRecord != nullptr)
     860              :                         {
     861              :                             // finish up any current (previous) pin records
     862        11045 :                             if (pCurrentPinRecord != nullptr)
     863              :                             {
     864              :                                 // check for overflow
     865        10985 :                                 if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
     866              :                                                                 {
     867            0 :                                                                         throw_parse_error(m_path, line, token, lineNumber);
     868              :                                                                 }
     869        10985 :                                 pCurrentPinRecord->index = static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
     870        10985 :                                 pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
     871        10985 :                                 pCurrentPinRecord.reset();
     872              :                             }
     873              : 
     874              :                             // finish up any current (previous) package records
     875        11045 :                             m_packageRecords.push_back(pCurrentPackageRecord);
     876              :                             //m_packageRecordsByName[pCurrentPackageRecord->name] = pCurrentPackageRecord;
     877        11045 :                             pCurrentPackageRecord.reset();
     878              :                         }
     879              : 
     880        11142 :                         pCurrentPackageRecord = std::make_shared<PackageRecord>();
     881        11142 :                         pCurrentPackageRecord->index = static_cast<unsigned int>(m_packageRecords.size());
     882              : 
     883              :                         // name
     884        11142 :                         if (!(lineStream >> pCurrentPackageRecord->name))
     885              :                         {
     886            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     887              :                         }
     888              : 
     889              :                         // pitch
     890        11142 :                         if (!(lineStream >> pCurrentPackageRecord->pitch))
     891              :                         {
     892            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     893              :                         }
     894              : 
     895              :                         // xmin, ymin
     896        11142 :                         if (!(lineStream >> pCurrentPackageRecord->xMin >> pCurrentPackageRecord->yMin))
     897              :                         {
     898            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     899              :                         }
     900              : 
     901              :                         // xmax
     902        11142 :                         if (!(lineStream >> pCurrentPackageRecord->xMax))
     903              :                         {
     904            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     905              :                         }
     906              : 
     907              :                         // ymax and attributes/ID string
     908        11142 :                         if (!std::getline(lineStream, token, ';'))
     909              :                         {
     910            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     911              :                         }
     912              : 
     913              :                         // ymax
     914        11142 :                         pCurrentPackageRecord->yMax = std::stof(token);
     915              : 
     916        11142 :                         std::string attrIdString;
     917        11142 :                         lineStream >> attrIdString;
     918        11142 :                         if (!pCurrentPackageRecord->ParseAttributeLookupTable(attrIdString, pCurrentPackageRecord->id))
     919              :                         {
     920            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     921              :                         }
     922        11142 :                     }
     923       453160 :                     else if (line.find(PIN_RECORD_TOKEN) == 0)
     924              :                     {
     925              :                         // package pin record line
     926       117070 :                         std::string token;
     927              : 
     928       117070 :                         if (!(lineStream >> token) || token != PIN_RECORD_TOKEN)
     929              :                         {
     930            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     931              :                         }
     932              : 
     933       117070 :                         if (pCurrentPackageRecord != nullptr)
     934              :                         {
     935              :                             // finish up any current (previous) pin records
     936       117070 :                             if (pCurrentPinRecord != nullptr)
     937              :                             {
     938              :                                 // check for overflow
     939       105988 :                                 if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
     940              :                                 {
     941            0 :                                     throw_parse_error(m_path, line, token, lineNumber);
     942              :                                 }
     943       105988 :                                 pCurrentPinRecord->index = static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
     944       105988 :                                 pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
     945       105988 :                                 pCurrentPinRecord.reset();
     946              :                             }                            
     947              :                         }
     948              : 
     949       117070 :                         pCurrentPinRecord = std::make_shared<PackageRecord::PinRecord>();
     950              :                         //pCurrentPinRecord->index = static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
     951              : 
     952              :                         // name
     953       117070 :                         lineStream >> pCurrentPinRecord->name;
     954              : 
     955              :                         // type
     956       117070 :                         if (!(lineStream >> token))
     957              :                         {
     958            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     959              :                         }
     960              : 
     961       117070 :                         if (token == "T")
     962              :                         {
     963         8683 :                             pCurrentPinRecord->type = PackageRecord::PinRecord::Type::ThroughHole;
     964              :                         }
     965       108387 :                         else if (token == "B")
     966              :                         {
     967            0 :                             pCurrentPinRecord->type = PackageRecord::PinRecord::Type::Blind;
     968              :                         }
     969       108387 :                         else if (token == "S")
     970              :                         {
     971       108385 :                             pCurrentPinRecord->type = PackageRecord::PinRecord::Type::Surface;
     972              :                         }
     973              :                         else
     974              :                         {
     975            4 :                             logerror("unknown pin type: [" + token + "]");
     976            2 :                             throw_parse_error(m_path, line, token, lineNumber);
     977              :                         }
     978              : 
     979              :                         // xc, xy
     980       117068 :                         if (!(lineStream >> pCurrentPinRecord->xCenter >> pCurrentPinRecord->yCenter))
     981              :                         {
     982            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     983              :                         }
     984              : 
     985              :                         // finished hole size (fhs)
     986       117068 :                         if (!(lineStream >> pCurrentPinRecord->finishedHoleSize))
     987              :                         {
     988            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     989              :                         }
     990              : 
     991              :                         // electrical type
     992       117068 :                         if (!(lineStream >> token))
     993              :                         {
     994            0 :                             throw_parse_error(m_path, line, token, lineNumber);
     995              :                         }
     996              : 
     997       117068 :                         if (token == "E")
     998              :                         {
     999            0 :                             pCurrentPinRecord->electricalType = PackageRecord::PinRecord::ElectricalType::Electrical;
    1000              :                         }
    1001       117068 :                         else if (token == "M")
    1002              :                         {
    1003            0 :                             pCurrentPinRecord->electricalType = PackageRecord::PinRecord::ElectricalType::NonElectrical;
    1004              :                         }
    1005       117068 :                         else if (token == "U")
    1006              :                         {
    1007       117067 :                             pCurrentPinRecord->electricalType = PackageRecord::PinRecord::ElectricalType::Undefined;
    1008              :                         }
    1009              :                         else
    1010              :                         {
    1011            2 :                             logerror("unknown pin electrical type: [" + token + "]");
    1012            1 :                             throw_parse_error(m_path, line, token, lineNumber);
    1013              :                         }
    1014              : 
    1015              :                         // mount type
    1016       117067 :                         if (!(lineStream >> token))
    1017              :                         {
    1018            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1019              :                         }
    1020              : 
    1021       117067 :                         if (token == "S")
    1022              :                         {
    1023            0 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::Smt;
    1024              :                         }
    1025       117067 :                         else if (token == "D")
    1026              :                         {
    1027            0 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::RecommendedSmtPad;
    1028              :                         }
    1029       117067 :                         else if (token == "T")
    1030              :                         {
    1031            0 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::MT_ThroughHole;
    1032              :                         }
    1033       117067 :                         else if (token == "R")
    1034              :                         {
    1035            0 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::RecommendedThroughHole;
    1036              :                         }
    1037       117067 :                         else if (token == "P")
    1038              :                         {
    1039            0 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::Pressfit;
    1040              :                         }
    1041       117067 :                         else if (token == "N")
    1042              :                         {
    1043            0 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::NonBoard;
    1044              :                         }
    1045       117067 :                         else if (token == "H")
    1046              :                         {
    1047            0 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::Hole;
    1048              :                         }
    1049       117067 :                         else if (token == "U")
    1050              :                         {
    1051       117067 :                             pCurrentPinRecord->mountType = PackageRecord::PinRecord::MountType::MT_Undefined;
    1052              :                         }
    1053              :                         else
    1054              :                         {
    1055            0 :                             logerror("unknown pin mount type: [" + token + "]");
    1056            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1057              :                         }
    1058              : 
    1059              :                         // ID=<id>
    1060              :                         // PIN record, ID field is optional: spec pg.31
    1061       117067 :                         if (lineStream >> token)
    1062              :                         {
    1063       117067 :                             std::stringstream idStream(token);
    1064       117067 :                             if (!std::getline(idStream, token, '=') || token != "ID")
    1065              :                             {
    1066            0 :                                 throw_parse_error(m_path, line, token, lineNumber);
    1067              :                             }
    1068              : 
    1069       117067 :                             idStream >> pCurrentPinRecord->id;
    1070       117067 :                         }
    1071              :                         else
    1072              :                         {
    1073              : 
    1074              : #define SIMULATE_PARSE_ERROR 0
    1075              : #if SIMULATE_PARSE_ERROR
    1076              :                             throw_parse_error(m_path, line, token, lineNumber);
    1077              : #endif
    1078              : 
    1079            0 :                             pCurrentPinRecord->id = UINT_MAX;
    1080              :                         }                        
    1081       117070 :                     }
    1082       336090 :                     else if (line.find(FEATURE_GROUP_RECORD_TOKEN) == 0)
    1083              :                     {
    1084              :                         // feature group record line
    1085            0 :                         std::string token;
    1086              : 
    1087            0 :                         if (!(lineStream >> token))
    1088              :                         {
    1089            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1090              :                         }
    1091              :                         
    1092            0 :                         if (token != FEATURE_GROUP_RECORD_TOKEN)
    1093              :                         {
    1094            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1095              :                         }
    1096              : 
    1097              :                         // finish current (previous) net record
    1098            0 :                         if (pCurrentNetRecord != nullptr)
    1099              :                         {
    1100              :                             // finish up (any) current subnet record
    1101            0 :                             if (pCurrentSubnetRecord != nullptr)
    1102              :                             {
    1103            0 :                                 pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
    1104            0 :                                 pCurrentSubnetRecord.reset();
    1105              :                             }
    1106              : 
    1107            0 :                             m_netRecords.push_back(pCurrentNetRecord);
    1108              :                             //m_netRecordsByName[pCurrentNetRecord->name] = pCurrentNetRecord;
    1109            0 :                             pCurrentNetRecord.reset();
    1110              :                         }
    1111            0 :                         else if (pCurrentPackageRecord != nullptr)
    1112              :                         {
    1113              :                             // finish up any current (previous) pin records
    1114            0 :                             if (pCurrentPinRecord != nullptr)
    1115              :                             {
    1116              :                                 // check for overflow
    1117            0 :                                 if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
    1118              :                                 {
    1119            0 :                                     throw_parse_error(m_path, line, token, lineNumber);
    1120              :                                 }
    1121            0 :                                 pCurrentPinRecord->index = static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
    1122            0 :                                 pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
    1123            0 :                                 pCurrentPinRecord.reset();
    1124              :                             }
    1125              : 
    1126              :                             // finish up any current (previous) package records
    1127            0 :                             m_packageRecords.push_back(pCurrentPackageRecord);
    1128              :                             //m_packageRecordsByName[pCurrentPackageRecord->name] = pCurrentPackageRecord;
    1129            0 :                             pCurrentPackageRecord.reset();
    1130              :                         }                        
    1131            0 :                         else if (pCurrentFeatureGroupRecord != nullptr)
    1132              :                         {
    1133            0 :                             m_featureGroupRecords.push_back(pCurrentFeatureGroupRecord);
    1134            0 :                             pCurrentFeatureGroupRecord.reset();
    1135              :                         }
    1136              : 
    1137            0 :                         pCurrentFeatureGroupRecord = std::make_shared<FeatureGroupRecord>();
    1138              : 
    1139            0 :                         if (!(lineStream >> pCurrentFeatureGroupRecord->type))
    1140              :                         {
    1141            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1142              :                         }                                                
    1143            0 :                     }
    1144       336090 :                     else if (line.find(PackageRecord::OutlineRecord::RECTANGLE_RECORD_TOKEN) == 0)
    1145              :                     {                        
    1146        57594 :                         std::string token;                        
    1147        57594 :                         if (!(lineStream >> token))
    1148              :                         {
    1149            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1150              :                         }
    1151              : 
    1152        57594 :                         if (token != PackageRecord::OutlineRecord::RECTANGLE_RECORD_TOKEN)
    1153              :                         {
    1154            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1155              :                         }
    1156              : 
    1157        57594 :                         auto pOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
    1158        57594 :                         pOutlineRecord->type = PackageRecord::OutlineRecord::Type::Rectangle;
    1159              : 
    1160        57594 :                         if (!(lineStream >> pOutlineRecord->lowerLeftX))
    1161              :                         {
    1162            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1163              :                         }
    1164              : 
    1165        57594 :                         if (!(lineStream >> pOutlineRecord->lowerLeftY))
    1166              :                         {
    1167            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1168              :                         }
    1169              : 
    1170        57594 :                         if (!(lineStream >> pOutlineRecord->width))
    1171              :                         {
    1172            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1173              :                         }
    1174              : 
    1175        57594 :                         if (!(lineStream >> pOutlineRecord->height))
    1176              :                         {
    1177            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1178              :                         }
    1179              : 
    1180        57594 :                         if (pCurrentPackageRecord != nullptr)
    1181              :                         {
    1182        57594 :                             if (pCurrentPinRecord != nullptr)
    1183              :                             {
    1184        52677 :                                 pCurrentPinRecord->m_outlineRecords.push_back(pOutlineRecord);
    1185              :                             }
    1186              :                             else
    1187              :                             {
    1188         4917 :                                 pCurrentPackageRecord->m_outlineRecords.push_back(pOutlineRecord);
    1189              :                             }
    1190              :                         }
    1191              :                         else
    1192              :                         {
    1193            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1194              :                         }
    1195        57594 :                     }
    1196       278496 :                     else if (line.find(PackageRecord::OutlineRecord::CIRCLE_RECORD_TOKEN) == 0)
    1197              :                     {
    1198        51920 :                         std::string token;
    1199        51920 :                         if (!(lineStream >> token))
    1200              :                         {
    1201            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1202              :                         }
    1203              : 
    1204        51920 :                         if (token != PackageRecord::OutlineRecord::CIRCLE_RECORD_TOKEN)
    1205              :                         {
    1206            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1207              :                         }
    1208              : 
    1209        51920 :                         auto pOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
    1210        51920 :                         pOutlineRecord->type = PackageRecord::OutlineRecord::Type::Circle;
    1211              : 
    1212        51920 :                         if (!(lineStream >> pOutlineRecord->xCenter))
    1213              :                         {
    1214            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1215              :                         }
    1216              : 
    1217        51920 :                         if (!(lineStream >> pOutlineRecord->yCenter))
    1218              :                         {
    1219            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1220              :                         }
    1221              : 
    1222        51920 :                         if (!(lineStream >> pOutlineRecord->radius))
    1223              :                         {
    1224            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1225              :                         }                        
    1226              : 
    1227        51920 :                         if (pCurrentPackageRecord != nullptr)
    1228              :                         {
    1229        51920 :                             if (pCurrentPinRecord != nullptr)
    1230              :                             {
    1231        49257 :                                 pCurrentPinRecord->m_outlineRecords.push_back(pOutlineRecord);
    1232              :                             }
    1233              :                             else
    1234              :                             {
    1235         2663 :                                 pCurrentPackageRecord->m_outlineRecords.push_back(pOutlineRecord);
    1236              :                             }
    1237              :                         }
    1238              :                         else
    1239              :                         {
    1240            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1241              :                         }
    1242        51920 :                     }
    1243       226576 :                     else if (line.find(PackageRecord::OutlineRecord::SQUARE_RECORD_TOKEN) == 0)
    1244              :                     {
    1245         1110 :                         std::string token;
    1246         1110 :                         if (!(lineStream >> token))
    1247              :                         {
    1248            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1249              :                         }
    1250              : 
    1251         1110 :                         if (token != PackageRecord::OutlineRecord::SQUARE_RECORD_TOKEN)
    1252              :                         {
    1253            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1254              :                         }
    1255              : 
    1256         1110 :                         auto pOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
    1257         1110 :                         pOutlineRecord->type = PackageRecord::OutlineRecord::Type::Square;
    1258              : 
    1259         1110 :                         if (!(lineStream >> pOutlineRecord->xCenter))
    1260              :                         {
    1261            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1262              :                         }
    1263              : 
    1264         1110 :                         if (!(lineStream >> pOutlineRecord->yCenter))
    1265              :                         {
    1266            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1267              :                         }
    1268              : 
    1269         1110 :                         if (!(lineStream >> pOutlineRecord->halfSide))
    1270              :                         {
    1271            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1272              :                         }
    1273              : 
    1274         1110 :                         if (pCurrentPackageRecord != nullptr)
    1275              :                         {
    1276         1110 :                             if (pCurrentPinRecord != nullptr)
    1277              :                             {
    1278          481 :                                 pCurrentPinRecord->m_outlineRecords.push_back(pOutlineRecord);
    1279              :                             }
    1280              :                             else
    1281              :                             {
    1282          629 :                                 pCurrentPackageRecord->m_outlineRecords.push_back(pOutlineRecord);
    1283              :                             }
    1284              :                         }
    1285              :                         else
    1286              :                         {
    1287            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1288              :                         }
    1289         1110 :                     }
    1290       225466 :                     else if (line.find(PackageRecord::OutlineRecord::CONTOUR_BEGIN_RECORD_TOKEN) == 0)
    1291              :                     {
    1292        17585 :                         std::string token;
    1293        17585 :                         if (!(lineStream >> token))
    1294              :                         {
    1295            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1296              :                         }
    1297              : 
    1298        17585 :                         if (token != PackageRecord::OutlineRecord::CONTOUR_BEGIN_RECORD_TOKEN)
    1299              :                         {
    1300            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1301              :                         }
    1302              : 
    1303        17585 :                         pCurrentContourOutlineRecord = std::make_shared<PackageRecord::OutlineRecord>();
    1304        17585 :                         pCurrentContourOutlineRecord->type = PackageRecord::OutlineRecord::Type::Contour;
    1305        17585 :                     }
    1306       207881 :                                         else if (line.find(PackageRecord::OutlineRecord::CONTOUR_END_RECORD_TOKEN) == 0)
    1307              :                                         {
    1308        17585 :                                                 std::string token;
    1309        17585 :                                                 if (!(lineStream >> token))
    1310              :                                                 {
    1311            0 :                                                         throw_parse_error(m_path, line, token, lineNumber);
    1312              :                                                 }
    1313              : 
    1314        17585 :                                                 if (token != PackageRecord::OutlineRecord::CONTOUR_END_RECORD_TOKEN)
    1315              :                                                 {
    1316            0 :                                                         throw_parse_error(m_path, line, token, lineNumber);
    1317              :                                                 }                        
    1318              : 
    1319        17585 :                                                 if (pCurrentPackageRecord != nullptr)
    1320              :                                                 {
    1321        17585 :                                                         if (pCurrentPinRecord != nullptr)
    1322              :                                                         {
    1323        14652 :                                                                 pCurrentPinRecord->m_outlineRecords.push_back(pCurrentContourOutlineRecord);
    1324              :                                                         }
    1325              :                                                         else
    1326              :                                                         {
    1327         2933 :                                                                 pCurrentPackageRecord->m_outlineRecords.push_back(pCurrentContourOutlineRecord);
    1328              :                                                         }
    1329              :                                                 }
    1330              :                                                 else
    1331              :                                                 {
    1332            0 :                                                         throw_parse_error(m_path, line, token, lineNumber);
    1333              :                                                 }
    1334              : 
    1335        17585 :                                                 pCurrentContourOutlineRecord.reset();
    1336        17585 :                                         }
    1337       190296 :                     else if (line.find(ContourPolygon::BEGIN_RECORD_TOKEN) == 0)
    1338              :                     {
    1339        17585 :                         std::string token;
    1340        17585 :                         if (!(lineStream >> token))
    1341              :                         {
    1342            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1343              :                         }
    1344              : 
    1345        17585 :                         if (token != ContourPolygon::BEGIN_RECORD_TOKEN)
    1346              :                         {
    1347            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1348              :                         }
    1349              : 
    1350        17585 :                         pCurrentContourPolygon = std::make_shared<ContourPolygon>();
    1351              : 
    1352        17585 :                         if (!(lineStream >> pCurrentContourPolygon->xStart))
    1353              :                         {
    1354            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1355              :                         }
    1356              : 
    1357        17585 :                         if (!(lineStream >> pCurrentContourPolygon->yStart))
    1358              :                         {
    1359            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1360              :                         }
    1361              : 
    1362        17585 :                         if (!(lineStream >> token))
    1363              :                         {
    1364            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1365              :                         }
    1366              : 
    1367        17585 :                         if (token == ContourPolygon::ISLAND_TYPE_TOKEN)
    1368              :                         {
    1369        17585 :                             pCurrentContourPolygon->type = ContourPolygon::Type::Island;
    1370              :                         }
    1371            0 :                         else if (token == ContourPolygon::HOLE_TYPE_TOKEN)
    1372              :                         {
    1373            0 :                             pCurrentContourPolygon->type = ContourPolygon::Type::Hole;
    1374              :                         }
    1375              :                         else
    1376              :                         {
    1377            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1378              :                         }
    1379        17585 :                     }
    1380       172711 :                     else if (line.find(ContourPolygon::END_RECORD_TOKEN) == 0)
    1381              :                     {
    1382        17585 :                         std::string token;
    1383        17585 :                         if (!(lineStream >> token))
    1384              :                         {
    1385            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1386              :                         }
    1387              : 
    1388        17585 :                         if (token != ContourPolygon::END_RECORD_TOKEN)
    1389              :                         {
    1390            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1391              :                         }
    1392              : 
    1393        17585 :                         if (pCurrentContourOutlineRecord != nullptr)
    1394              :                         {
    1395        17585 :                             pCurrentContourOutlineRecord->m_contourPolygons.push_back(pCurrentContourPolygon);
    1396        17585 :                             pCurrentContourPolygon.reset();
    1397              :                         }
    1398              :                                                 else
    1399              :                                                 {
    1400            0 :                                                         throw_parse_error(m_path, line, token, lineNumber);
    1401              :                                                 }
    1402        17585 :                     }
    1403       155126 :                     else if (line.find(ContourPolygon::PolygonPart::ARC_RECORD_TOKEN) == 0)
    1404              :                     {
    1405        60670 :                         std::string token;
    1406        60670 :                         if (!(lineStream >> token))
    1407              :                         {
    1408            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1409              :                         }
    1410              : 
    1411        60670 :                         if (token != ContourPolygon::PolygonPart::ARC_RECORD_TOKEN)
    1412              :                         {
    1413            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1414              :                         }
    1415              : 
    1416        60670 :                         auto pPolygonPart = std::make_shared<ContourPolygon::PolygonPart>();
    1417        60670 :                         pPolygonPart->type = ContourPolygon::PolygonPart::Type::Arc;
    1418              : 
    1419        60670 :                         if (!(lineStream >> pPolygonPart->endX))
    1420              :                         {
    1421            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1422              :                         }                        
    1423              : 
    1424        60670 :                         if (!(lineStream >> pPolygonPart->endY))
    1425              :                         {
    1426            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1427              :                         }
    1428              : 
    1429        60670 :                         if (!(lineStream >> pPolygonPart->xCenter))
    1430              :                         {
    1431            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1432              :                         }
    1433              : 
    1434        60670 :                         if (!(lineStream >> pPolygonPart->yCenter))
    1435              :                         {
    1436            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1437              :                         }
    1438              : 
    1439        60670 :                         if (!(lineStream >> token))
    1440              :                         {
    1441            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1442              :                         }
    1443              : 
    1444        60670 :                         if (token == "y" || token == "Y")
    1445              :                         {
    1446        60411 :                             pPolygonPart->isClockwise = true;
    1447              :                         }
    1448          259 :                         else if (token == "n" || token == "N")
    1449              :                         {
    1450          259 :                             pPolygonPart->isClockwise = false;
    1451              :                         }
    1452              :                         else
    1453              :                         {
    1454            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1455              :                         }
    1456              : 
    1457        60670 :                         if (pCurrentContourPolygon != nullptr)
    1458              :                         {
    1459        60670 :                             pCurrentContourPolygon->m_polygonParts.push_back(pPolygonPart);
    1460              :                         }
    1461              :                         else
    1462              :                         {
    1463            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1464              :                         }
    1465        60670 :                     }
    1466        94456 :                     else if (line.find(ContourPolygon::PolygonPart::SEGMENT_RECORD_TOKEN) == 0)
    1467              :                     {
    1468        94456 :                         std::string token;
    1469        94456 :                         if (!(lineStream >> token))
    1470              :                         {
    1471            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1472              :                         }
    1473              : 
    1474        94456 :                         if (token != ContourPolygon::PolygonPart::SEGMENT_RECORD_TOKEN)
    1475              :                         {
    1476            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1477              :                         }
    1478              : 
    1479        94456 :                         auto pPolygonPart = std::make_shared<ContourPolygon::PolygonPart>();
    1480        94456 :                         pPolygonPart->type = ContourPolygon::PolygonPart::Type::Segment;
    1481              : 
    1482        94456 :                         if (!(lineStream >> pPolygonPart->endX))
    1483              :                         {
    1484            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1485              :                         }
    1486              : 
    1487        94456 :                         if (!(lineStream >> pPolygonPart->endY))
    1488              :                         {
    1489            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1490              :                         }                        
    1491              : 
    1492        94456 :                         if (pCurrentContourPolygon != nullptr)
    1493              :                         {
    1494        94456 :                             pCurrentContourPolygon->m_polygonParts.push_back(pPolygonPart);
    1495              :                         }
    1496              :                         else
    1497              :                         {
    1498            0 :                             throw_parse_error(m_path, line, token, lineNumber);
    1499              :                         }
    1500        94456 :                     }
    1501              :                     else
    1502              :                     {
    1503              :                         // unrecognized record line
    1504            0 :                         parse_info pi(m_path, line, lineNumber);
    1505            0 :                         logwarn(pi.toString("unrecognized record line in EDADATA file:"));                        
    1506            0 :                     }
    1507      7518517 :                 }
    1508              :                 else
    1509              :                 {
    1510              :                     // empty line
    1511            0 :                     continue;                    
    1512              :                 }
    1513              :             }
    1514              : 
    1515              :             // finish current (previous) net record
    1516              :             // this is the case where the last line of the file is not a net record (and there are no PKG records)
    1517           94 :             if (pCurrentNetRecord != nullptr)
    1518              :             {
    1519              :                 // finish current (previous) subnet record
    1520              :                 // case where we reach the end of the file before a new net record is encountered (and there are no PKG records)
    1521            0 :                 if (pCurrentSubnetRecord != nullptr)
    1522              :                 {
    1523            0 :                     pCurrentNetRecord->m_subnetRecords.push_back(pCurrentSubnetRecord);
    1524            0 :                     pCurrentSubnetRecord.reset();
    1525              :                 }
    1526              : 
    1527            0 :                 m_netRecords.push_back(pCurrentNetRecord);
    1528              :                 //m_netRecordsByName[pCurrentNetRecord->name] = pCurrentNetRecord;
    1529            0 :                 pCurrentNetRecord.reset();
    1530              :             }
    1531           94 :             else if (pCurrentPackageRecord != nullptr)
    1532              :             {
    1533              :                 // finish up any current (previous) pin records
    1534           94 :                 if (pCurrentPinRecord != nullptr)
    1535              :                 {
    1536              :                     // check for overflow
    1537           94 :                     if (pCurrentPackageRecord->m_pinRecords.size() > UINT_MAX)
    1538              :                     {
    1539            0 :                         throw_parse_error(m_path, line, "", lineNumber);
    1540              :                     }
    1541           94 :                     pCurrentPinRecord->index = static_cast<unsigned>(pCurrentPackageRecord->m_pinRecords.size());
    1542           94 :                     pCurrentPackageRecord->m_pinRecords.push_back(pCurrentPinRecord);
    1543           94 :                     pCurrentPinRecord.reset();
    1544              :                 }
    1545              : 
    1546              :                 // finish up any current (previous) package records
    1547           94 :                 m_packageRecords.push_back(pCurrentPackageRecord);
    1548              :                 //m_packageRecordsByName[pCurrentPackageRecord->name] = pCurrentPackageRecord;
    1549           94 :                 pCurrentPackageRecord.reset();
    1550              :             }
    1551            0 :             else if (pCurrentFeatureGroupRecord != nullptr)
    1552              :             {
    1553            0 :                 m_featureGroupRecords.push_back(pCurrentFeatureGroupRecord);
    1554            0 :                 pCurrentFeatureGroupRecord.reset();
    1555              :             }
    1556              : 
    1557           94 :             edaDataFile.close();
    1558          115 :         }
    1559            3 :         catch (parse_error& pe)
    1560              :         {            
    1561            3 :             auto m = pe.toString("Parse Error:");
    1562            6 :             logerror(m);
    1563              :             // cleanup file
    1564            3 :             edaDataFile.close();
    1565            3 :             throw pe;
    1566            6 :         }
    1567            0 :         catch (std::exception& e)
    1568              :         {
    1569            0 :             parse_info pi(m_path, line, lineNumber);
    1570            0 :             const auto m = pi.toString();
    1571            0 :             logexception_msg(e, m);
    1572              :             // cleanup file
    1573            0 :             edaDataFile.close();
    1574            0 :             throw e;
    1575            0 :         }
    1576              : 
    1577           94 :         return true;
    1578          100 :     }       
    1579              : 
    1580              :     // Inherited via IProtoBuffable
    1581              :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord>
    1582         8533 :     EdaDataFile::PackageRecord::to_protobuf() const
    1583              :     {
    1584         8533 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord> pPackageRecordMessage(new Odb::Lib::Protobuf::EdaDataFile::PackageRecord);
    1585        17066 :         pPackageRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
    1586         8533 :         pPackageRecordMessage->set_pitch(pitch);
    1587         8533 :         pPackageRecordMessage->set_xmin(xMin);
    1588         8533 :         pPackageRecordMessage->set_ymin(yMin);
    1589         8533 :         pPackageRecordMessage->set_xmax(xMax);
    1590         8533 :         pPackageRecordMessage->set_ymax(yMax);
    1591         8533 :         if (id.has_value())
    1592              :         {
    1593            2 :             pPackageRecordMessage->set_id(*id);
    1594              :         }
    1595              :         //pPackageRecordMessage->set_attributesidstring(attributesIdString);
    1596       109602 :         for (const auto& pinRecord : m_pinRecords)
    1597              :         {
    1598       101069 :             auto pPinRecordMessage = pPackageRecordMessage->add_pinrecords();
    1599       101069 :             pPinRecordMessage->CopyFrom(*pinRecord->to_protobuf());
    1600              :         }
    1601         8533 :         for (const auto& kvPinRecord : m_pinRecordsByName)
    1602              :         {
    1603            0 :             (*pPackageRecordMessage->mutable_pinrecordsbyname())[Odb::Lib::Text::ToUtf8(kvPinRecord.first)] = *kvPinRecord.second->to_protobuf();
    1604              :         }
    1605        22257 :         for (const auto& propertyRecord : m_propertyRecords)
    1606              :         {
    1607        13724 :             auto pPropertyRecordMessage = pPackageRecordMessage->add_propertyrecords();
    1608        13724 :             pPropertyRecordMessage->CopyFrom(*propertyRecord->to_protobuf());
    1609              :         }
    1610        17064 :         for (const auto& outlineRecord : m_outlineRecords)
    1611              :         {
    1612         8531 :                         auto pOutlineRecordMessage = pPackageRecordMessage->add_outlinerecords();
    1613         8531 :                         pOutlineRecordMessage->CopyFrom(*outlineRecord->to_protobuf());
    1614              :                 }
    1615        17064 :         for (const auto& kvAttributeAssignment : m_attributeLookupTable)
    1616              :         {
    1617         8531 :             (*pPackageRecordMessage->mutable_attributelookuptable())[Odb::Lib::Text::ToUtf8(kvAttributeAssignment.first)] = Odb::Lib::Text::ToUtf8(kvAttributeAssignment.second);
    1618              :         }
    1619         8533 :         return pPackageRecordMessage;
    1620            0 :     }
    1621              : 
    1622          587 :     void EdaDataFile::PackageRecord::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::PackageRecord& message)
    1623              :     {
    1624          587 :         name = message.name();
    1625          587 :         pitch = message.pitch();
    1626          587 :         xMin = message.xmin();
    1627          587 :         yMin = message.ymin();
    1628          587 :         xMax = message.xmax();
    1629          587 :         yMax = message.ymax();
    1630          587 :         if (message.has_id())
    1631              :         {
    1632            2 :             id = message.id();
    1633              :         }
    1634              :         //attributesIdString = message.attributesidstring();
    1635              : 
    1636         6670 :         for (const auto& pinRecordMessage : message.pinrecords())
    1637              :         {
    1638         6083 :                         auto pPinRecord = std::make_shared<PinRecord>();
    1639         6083 :                         pPinRecord->from_protobuf(pinRecordMessage);
    1640         6083 :                         m_pinRecords.push_back(pPinRecord);                     
    1641         6083 :                 }
    1642              : 
    1643          587 :         for (const auto& kvPinRecordMessage : message.pinrecordsbyname())
    1644              :         {
    1645            0 :             auto pPinRecord = std::make_shared<PinRecord>();
    1646            0 :             pPinRecord->from_protobuf(kvPinRecordMessage.second);
    1647            0 :             m_pinRecordsByName[kvPinRecordMessage.first] = pPinRecord;
    1648            0 :         }
    1649              : 
    1650         1151 :         for (const auto& propertyRecordMessage : message.propertyrecords())
    1651              :         {
    1652          564 :                         auto pPropertyRecord = std::make_shared<PropertyRecord>();
    1653          564 :                         pPropertyRecord->from_protobuf(propertyRecordMessage);
    1654          564 :                         m_propertyRecords.push_back(pPropertyRecord);
    1655          564 :                 }
    1656              : 
    1657         1172 :         for (const auto& outlineRecordMessage : message.outlinerecords())
    1658              :         {
    1659          585 :             auto pOutlineRecord = std::make_shared<OutlineRecord>();
    1660          585 :             pOutlineRecord->from_protobuf(outlineRecordMessage);
    1661          585 :             m_outlineRecords.push_back(pOutlineRecord);
    1662          585 :         }
    1663              : 
    1664         1757 :         for (const auto& kvAttributeAssignment : message.attributelookuptable())
    1665              :         {
    1666          585 :             m_attributeLookupTable[kvAttributeAssignment.first] = kvAttributeAssignment.second;
    1667              :         }
    1668          587 :     }
    1669              : 
    1670              :     // Inherited via IProtoBuffable
    1671         8531 :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord> EdaDataFile::PackageRecord::OutlineRecord::to_protobuf() const
    1672              :     {
    1673         8531 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord> pOutlineRecordMessage(new Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord);
    1674         8531 :                 pOutlineRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord::Type)type);
    1675         8531 :                 pOutlineRecordMessage->set_lowerleftx(lowerLeftX);
    1676         8531 :                 pOutlineRecordMessage->set_lowerlefty(lowerLeftY);
    1677         8531 :                 pOutlineRecordMessage->set_width(width);
    1678         8531 :                 pOutlineRecordMessage->set_height(height);
    1679         8531 :                 pOutlineRecordMessage->set_xcenter(xCenter);
    1680         8531 :                 pOutlineRecordMessage->set_ycenter(yCenter);
    1681         8531 :                 pOutlineRecordMessage->set_radius(radius);
    1682         8531 :                 pOutlineRecordMessage->set_halfside(halfSide);
    1683        11316 :         for (const auto& contourPolygon : m_contourPolygons)
    1684              :         {
    1685         2785 :                         auto pContourPolygonMessage = pOutlineRecordMessage->add_contourpolygons();
    1686         2785 :                         pContourPolygonMessage->CopyFrom(*contourPolygon->to_protobuf());
    1687              :                 }
    1688         8531 :                 return pOutlineRecordMessage;
    1689            0 :     }
    1690              : 
    1691          585 :     void EdaDataFile::PackageRecord::OutlineRecord::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::PackageRecord::OutlineRecord& message)
    1692              :     {
    1693          585 :         type = (Type)message.type();
    1694          585 :                 lowerLeftX = message.lowerleftx();
    1695          585 :                 lowerLeftY = message.lowerlefty();
    1696          585 :                 width = message.width();
    1697          585 :                 height = message.height();
    1698          585 :                 xCenter = message.xcenter();
    1699          585 :                 yCenter = message.ycenter();
    1700          585 :                 radius = message.radius();
    1701          585 :                 halfSide = message.halfside();
    1702          736 :         for (const auto& contourPolygonMessage : message.contourpolygons())
    1703              :         {
    1704          151 :                         auto pContourPolygon = std::make_shared<ContourPolygon>();
    1705          151 :                         pContourPolygon->from_protobuf(contourPolygonMessage);
    1706          151 :                         m_contourPolygons.push_back(pContourPolygon);
    1707          151 :                 }
    1708          585 :     }
    1709              : 
    1710              :     // Inherited via IProtoBuffable
    1711              :     std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord>
    1712       101069 :     EdaDataFile::PackageRecord::PinRecord::to_protobuf() const
    1713              :     {
    1714       101069 :         std::unique_ptr<Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord> pPinRecordMessage(new Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord);
    1715       202138 :         pPinRecordMessage->set_name(Odb::Lib::Text::ToUtf8(name));
    1716       101069 :         pPinRecordMessage->set_type((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord::Type)type);
    1717       101069 :         pPinRecordMessage->set_xcenter(xCenter);
    1718       101069 :         pPinRecordMessage->set_ycenter(yCenter);
    1719       101069 :         pPinRecordMessage->set_finishedholesize(finishedHoleSize);
    1720       101069 :         pPinRecordMessage->set_electricaltype((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord::ElectricalType)electricalType);
    1721       101069 :         pPinRecordMessage->set_mounttype((Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord::MountType)mountType);
    1722       101069 :         pPinRecordMessage->set_id(id);
    1723       101069 :         pPinRecordMessage->set_index(index);
    1724       101069 :         return pPinRecordMessage;
    1725            0 :     }
    1726              : 
    1727         6083 :     void EdaDataFile::PackageRecord::PinRecord::from_protobuf(const Odb::Lib::Protobuf::EdaDataFile::PackageRecord::PinRecord& message)
    1728              :     {
    1729         6083 :         name = message.name();
    1730         6083 :         type = (Type)message.type();
    1731         6083 :         xCenter = message.xcenter();
    1732         6083 :         yCenter = message.ycenter();
    1733         6083 :         finishedHoleSize = message.finishedholesize();
    1734         6083 :         electricalType = (ElectricalType)message.electricaltype();
    1735         6083 :         mountType = (MountType)message.mounttype();
    1736         6083 :         id = message.id();
    1737         6083 :         index = message.index();
    1738         6083 :     }
    1739              : }
        

Generated by: LCOV version 2.0-1