58static std::vector<ODB_TOOL_RECORD>
parseOdbTools(
const fs::path& aToolsFile )
60 std::vector<ODB_TOOL_RECORD>
tools;
61 std::ifstream stream( aToolsFile );
64 auto value = [](
const std::string& aLine ) -> std::string
66 return aLine.substr( aLine.find(
'=' ) + 1 );
69 while( std::getline( stream, line ) )
71 const size_t start = line.find_first_not_of(
" \t" );
73 if( start == std::string::npos )
76 line = line.substr( start );
78 if( line.rfind(
"TOOLS", 0 ) == 0 )
80 else if(
tools.empty() )
82 else if( line.rfind(
"NUM=", 0 ) == 0 )
83 tools.back().m_num = std::stoi( value( line ) );
84 else if( line.rfind(
"FINISH_SIZE=", 0 ) == 0 )
85 tools.back().m_finishSize = std::stod( value( line ) );
86 else if( line.rfind(
"DRILL_SIZE=", 0 ) == 0 )
87 tools.back().m_drillSize = std::stod( value( line ) );
104 std::set<double> expectedSizes;
105 int npthHoleCount = 0;
107 for(
const PAD*
pad : board->GetPads() )
112 expectedSizes.insert(
pcbIUScale.IUTomm( std::min(
pad->GetDrillSizeX(),
pad->GetDrillSizeY() ) )
118 BOOST_REQUIRE_GT( npthHoleCount, (
int) expectedSizes.size() );
119 BOOST_REQUIRE_GT( expectedSizes.size(), 1 );
123 BOOST_REQUIRE_NO_THROW(
ExportOdb( *board, tempDir.
Path(), aUnits ) );
127 for(
const fs::directory_entry& entry : fs::recursive_directory_iterator( tempDir.
Path() ) )
129 if( entry.is_regular_file() && entry.path().filename() ==
"tools"
130 && entry.path().parent_path().filename().string().find(
"non-plated" )
131 != std::string::npos )
133 toolsFile = entry.path();
138 BOOST_REQUIRE_MESSAGE( !toolsFile.empty(),
139 "ODB++ export produced no non-plated drill tools file" );
141 std::ifstream unitsStream( toolsFile );
142 std::string unitsLine;
143 BOOST_REQUIRE(
static_cast<bool>( std::getline( unitsStream, unitsLine ) ) );
144 BOOST_CHECK_EQUAL( unitsLine, std::string(
"UNITS=" ) + ( std::string( aUnits ) ==
"mm" ?
"MM" :
"INCH" ) );
148 std::set<int> seenNums;
149 std::set<double> seenSizes;
153 BOOST_CHECK_MESSAGE( seenNums.insert( tool.m_num ).second,
154 "Drill tool number " << tool.m_num <<
" is used twice" );
157 seenSizes.insert( tool.m_drillSize );
161 BOOST_REQUIRE_EQUAL( seenSizes.size(), expectedSizes.size() );
163 auto actual = seenSizes.begin();
164 auto expected = expectedSizes.begin();
166 while(
actual != seenSizes.end() )
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
fs::path ExportOdb(const BOARD &aBoard, const fs::path &aDir, const std::string &aUnits, const std::string &aSigfig, REPORTER *aReporter)
BOOST_CHECK_EQUAL(result, "25.4")