299 std::ifstream componentsFile;
305 m_directory = directory;
307 m_layerName = m_directory.filename().string();
321 loginfo(
"checking for extraction...");
323 std::filesystem::path componentsFilePath;
324 for (
const std::string componentsFilename : COMPONENTS_FILENAMES)
326 loginfo(
"trying components file: [" + componentsFilename +
"]...");
329 if (exists(componentsFilePath) && is_regular_file(componentsFilePath))
331 loginfo(
"found components file: [" + componentsFilePath.string() +
"]");
336 m_path = componentsFilePath;
338 loginfo(
"any extraction complete, parsing data...");
340 if (!std::filesystem::exists(m_path))
342 auto message =
"components file does not exist: [" + m_path.string() +
"]";
345 else if (!std::filesystem::is_regular_file(m_path))
347 auto message =
"components is not a file: [" + m_path.string() +
"]";
351 componentsFile.open(m_path.string(), std::ios::in);
352 if (!componentsFile.is_open())
354 auto message =
"unable to open components file: [" + m_path.string() +
"]";
358 std::shared_ptr<ComponentRecord> pCurrentComponentRecord;
359 std::shared_ptr<BomDescriptionRecord> pCurrentBomDescriptionRecord;
361 while (std::getline(componentsFile, line))
369 std::stringstream lineStream(line);
372 if (line.find(COMMENT_TOKEN) == 0)
376 else if (line.find(UNITS_TOKEN) == 0)
380 if (!std::getline(lineStream, token,
'='))
384 else if (!std::getline(lineStream, token,
'='))
391 else if (line.find(ID_TOKEN) == 0)
394 if (!std::getline(lineStream, token,
'='))
398 else if (!std::getline(lineStream, token,
'='))
402 m_id = std::stoul(token);
404 else if (line.find(ATTRIBUTE_NAME_TOKEN) == 0)
409 if (!std::getline(lineStream, token,
' '))
413 else if (!std::getline(lineStream, token,
' '))
417 m_attributeNames.push_back(token);
419 else if (line.find(ATTRIBUTE_VALUE_TOKEN) == 0)
423 if (!std::getline(lineStream, token,
' '))
427 else if (!std::getline(lineStream, token,
' '))
431 m_attributeTextValues.push_back(token);
444 if (pCurrentBomDescriptionRecord !=
nullptr)
447 m_bomDescriptionRecordsByCpn[pCurrentBomDescriptionRecord->cpn] = pCurrentBomDescriptionRecord;
448 pCurrentBomDescriptionRecord.reset();
452 if (pCurrentComponentRecord !=
nullptr)
455 m_componentRecords.push_back(pCurrentComponentRecord);
456 pCurrentComponentRecord.reset();
460 pCurrentComponentRecord = std::make_shared<ComponentRecord>();
462 lineStream >> pCurrentComponentRecord->pkgRef;
463 lineStream >> pCurrentComponentRecord->locationX;
464 lineStream >> pCurrentComponentRecord->locationY;
465 lineStream >> pCurrentComponentRecord->rotation;
468 lineStream >> mirror;
469 pCurrentComponentRecord->mirror = (mirror ==
'M');
471 lineStream >> pCurrentComponentRecord->compName;
472 lineStream >> pCurrentComponentRecord->partName;
475 if (m_componentRecords.size() > UINT_MAX)
480 pCurrentComponentRecord->index =
static_cast<unsigned int>(m_componentRecords.size());
482 std::string attrIdString;
483 lineStream >> attrIdString;
487 pCurrentComponentRecord->compName,
488 pCurrentComponentRecord->pkgRef,
491 if (!pCurrentComponentRecord->ParseAttributeLookupTable(attrIdString, pCurrentComponentRecord->id))
498 pCurrentComponentRecord->compName,
499 pCurrentComponentRecord->pkgRef,
500 pCurrentComponentRecord->GetAttributeLookupTable(),
507 if (!(lineStream >> token))
517 auto pPropertyRecord = std::make_shared<PropertyRecord>();
519 if (!(lineStream >> pPropertyRecord->name))
524 if (!(lineStream >> token))
535 if (!(lineStream >> token))
541 if (token.size() > 0 && token[0] ==
'\'')
547 if (token.size() > 0 && token[token.size() - 1] ==
'\'')
550 token.erase(token.size() - 1);
556 pPropertyRecord->value = token;
559 while (lineStream >> f)
561 pPropertyRecord->floatValues.push_back(f);
564 pCurrentComponentRecord->m_propertyRecords.push_back(pPropertyRecord);
576 auto pToeprintRecord = std::make_shared<ComponentRecord::ToeprintRecord>();
577 lineStream >> pToeprintRecord->pinNumber;
578 lineStream >> pToeprintRecord->locationX;
579 lineStream >> pToeprintRecord->locationY;
580 lineStream >> pToeprintRecord->rotation;
583 lineStream >> mirror;
584 pToeprintRecord->mirror = (mirror ==
'M' || mirror ==
'm');
586 lineStream >> pToeprintRecord->netNumber;
587 if (pToeprintRecord->netNumber == (
unsigned int)-1)
593 if (!m_allowToepintNetNumbersOfNegative1)
599 lineStream >> pToeprintRecord->subnetNumber;
600 if (pToeprintRecord->subnetNumber == (
unsigned int)-1)
606 if (!m_allowToepintNetNumbersOfNegative1)
612 lineStream >> pToeprintRecord->name;
614 pCurrentComponentRecord->m_toeprintRecords.push_back(pToeprintRecord);
627 if (pCurrentBomDescriptionRecord !=
nullptr)
629 m_bomDescriptionRecordsByCpn[pCurrentBomDescriptionRecord->cpn] = pCurrentBomDescriptionRecord;
630 pCurrentBomDescriptionRecord.reset();
633 pCurrentBomDescriptionRecord = std::make_shared<ComponentsFile::BomDescriptionRecord>();
644 if (pCurrentBomDescriptionRecord ==
nullptr)
649 if (!(lineStream >> pCurrentBomDescriptionRecord->ipn))
664 if (pCurrentBomDescriptionRecord ==
nullptr)
669 std::string description;
671 if (!(lineStream >> description))
677 pCurrentBomDescriptionRecord->descriptions.push_back(description);
688 if (pCurrentBomDescriptionRecord ==
nullptr)
693 if (!(lineStream >> pCurrentBomDescriptionRecord->vpl_vnd))
707 if (pCurrentBomDescriptionRecord ==
nullptr)
712 if (!(lineStream >> pCurrentBomDescriptionRecord->vpl_mpn))
726 if (pCurrentBomDescriptionRecord ==
nullptr)
731 if (!(lineStream >> pCurrentBomDescriptionRecord->vnd))
745 if (pCurrentBomDescriptionRecord ==
nullptr)
750 if (!(lineStream >> pCurrentBomDescriptionRecord->mpn))
762 if (pCurrentBomDescriptionRecord !=
nullptr)
765 m_bomDescriptionRecordsByCpn[pCurrentBomDescriptionRecord->cpn] = pCurrentBomDescriptionRecord;
766 pCurrentBomDescriptionRecord.reset();
770 if (pCurrentComponentRecord !=
nullptr)
773 m_componentRecords.push_back(pCurrentComponentRecord);
774 pCurrentComponentRecord.reset();
777 componentsFile.close();
781 auto m = pe.
toString(
"Parse Error:");
783 componentsFile.close();
786 catch (std::exception& e)
791 componentsFile.close();