37namespace fs = std::filesystem;
40fs::path
ExportOdb(
const BOARD& aBoard,
const fs::path& aDir,
const std::string& aUnits,
41 const std::string& aSigfig,
REPORTER* aReporter )
43 fs::create_directories( aDir );
50 std::map<std::string, UTF8> props;
51 props[
"units"] = aUnits;
52 props[
"sigfig"] = aSigfig;
54 odbExporter.
SaveBoard( wxString::FromUTF8( aDir.string() ),
const_cast<BOARD&
>( aBoard ), &props );
60std::vector<std::string>
ReadLines(
const fs::path& aFile )
62 std::vector<std::string> lines;
63 std::ifstream stream( aFile );
66 while( std::getline( stream, line ) )
67 lines.push_back( line );
76 std::istringstream stream( aLine );
77 std::vector<std::string> fields;
80 while( stream >> token )
81 fields.push_back( token );
89 static std::vector<std::unique_ptr<KI_TEST::SCOPED_TEMP_DIR>> dirs;
90 dirs.emplace_back( std::make_unique<KI_TEST::SCOPED_TEMP_DIR>( wxS(
"odb_attributes" ) ) );
101 for(
const PAD*
pad : footprint->Pads() )
103 if(
pad->GetProperty() == aProperty &&
pad->IsOnLayer( aLayer ) )
114 for(
const std::string& line :
ReadLines( aFile ) )
116 if( line.rfind(
"@", 0 ) == 0 )
118 size_t space = line.find(
' ' );
120 if( space != std::string::npos )
121 m_names.emplace( line.substr( space + 1 ), line.substr( 1, space - 1 ) );
123 else if( line.rfind(
"CMP ", 0 ) == 0
124 || ( line.size() > 2 && line[1] ==
' '
125 && ( line[0] ==
'P' || line[0] ==
'L' || line[0] ==
'A' || line[0] ==
'S' ) ) )
135 static const std::map<std::string, std::vector<std::string>> options = {
136 {
".pad_usage", {
"toeprint",
"via",
"g_fiducial",
"l_fiducial",
"tooling_hole",
"bond_finger" } },
137 {
".drill", {
"plated",
"non_plated",
"via" } },
138 {
".plated_type", {
"standard",
"press_fit" } },
139 {
".via_type", {
"drilled",
"laser",
"photo" } },
140 {
".comp_mount_type", {
"other",
"smd",
"tht",
"pressfit" } }
143 auto found = options.find( aName );
145 if( found == options.end() )
148 const auto& values = found->second;
149 auto option = std::find( values.begin(), values.end(), aOption );
151 if( option == values.end() )
179 for(
const std::string& record :
m_records )
181 size_t start = record.find(
';' );
183 if( start == std::string::npos )
186 std::stringstream attributes( record.substr( start + 1 ) );
187 std::string attribute;
189 while( std::getline( attributes, attribute,
',' ) )
191 if( attribute ==
name->second + ( aValue.empty() ?
"" :
"=" + aValue ) )
209 FILE_LINE_READER reader( wxString::FromUTF8( ( aRoot /
"matrix" /
"matrix" ).
string() ) );
211 while(
const char* line = reader.
ReadLine() )
213 wxString
text = wxString::FromUTF8( line ).Strip( wxString::both );
215 if(
text.EndsWith( wxS(
"{" ) ) )
217 block =
text.BeforeLast(
'{' ).Strip( wxString::both );
222 if(
text == wxS(
"}" ) )
224 if( block == wxS(
"LAYER" ) )
231 wxString key =
text.BeforeFirst(
'=' ).Strip( wxString::both );
232 wxString value =
text.AfterFirst(
'=' ).Strip( wxString::both );
234 if( block == wxS(
"STEP" ) && key == wxS(
"NAME" ) && stepName.IsEmpty() )
238 else if( block == wxS(
"LAYER" ) )
240 if( key == wxS(
"ROW" ) )
241 row.
m_row = wxAtoi( value );
242 else if( key == wxS(
"CONTEXT" ) )
244 else if( key == wxS(
"TYPE" ) )
246 else if( key == wxS(
"NAME" ) )
248 else if( key == wxS(
"POLARITY" ) )
250 else if( key == wxS(
"START_NAME" ) )
252 else if( key == wxS(
"END_NAME" ) )
254 else if( key == wxS(
"ADD_TYPE" ) )
256 else if( key == wxS(
"ID" ) )
258 else if( key == wxS(
"REF" ) )
260 else if( key == wxS(
"CU_TOP" ) )
262 else if( key == wxS(
"CU_BOTTOM" ) )
264 else if( key == wxS(
"DIELECTRIC_TYPE" ) )
271 for(
const fs::directory_entry& entry : fs::directory_iterator( aRoot /
"steps", ec ) )
273 if( entry.is_directory() && wxString::FromUTF8( entry.path().filename().string() ).IsSameAs( stepName,
false ) )
281 fs::path layersRoot =
m_stepDir /
"layers";
282 fs::path layerDir = layersRoot / aLayer.Lower().ToStdString();
285 for(
const fs::directory_entry& entry : fs::directory_iterator( layersRoot, ec ) )
287 if( entry.is_directory() && wxString::FromUTF8( entry.path().filename().string() ).IsSameAs( aLayer,
false ) )
288 layerDir = entry.path();
291 return wxString::FromUTF8( ( layerDir / aFile.ToStdString() ).string() );
Information pertinent to a Pcbnew printed circuit board.
const FOOTPRINTS & Footprints() const
A LINE_READER that reads from an open file.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
std::vector< ODB_MATRIX_ROW > m_matrix
std::filesystem::path m_stepDir
wxString LayerFile(const wxString &aLayer, const wxString &aFile) const
Path of a file in a layer directory, matched to the directory name without regard to case.
ODB_PRODUCT(const std::filesystem::path &aRoot)
std::map< std::string, std::string > m_names
std::vector< std::string > m_records
size_t CountRecordsWithInteger(const std::string &aName, int aValue) const
size_t CountRecordsWithOption(const std::string &aName, const std::string &aOption) const
OdbFeatureFile(const std::filesystem::path &aFile)
size_t CountRecordsWithValue(const std::string &aName, const std::string &aValue) const
size_t CountRecordsWithFlag(const std::string &aName) const
void SaveBoard(const wxString &aFileName, BOARD &aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
A pure virtual class used to derive REPORTER objects from.
PCB_LAYER_ID
A quick note on layer IDs:
size_t CountPads(const BOARD &aBoard, PAD_PROP aProperty, PCB_LAYER_ID aLayer)
fs::path ExportOdb(const BOARD &aBoard, const fs::path &aDir, const std::string &aUnits, const std::string &aSigfig, REPORTER *aReporter)
std::vector< std::string > ReadLineFields(const std::string &aLine)
Return the tokenised fields of a line, split by whitespace.
std::vector< std::string > ReadLines(const fs::path &aFile)
const KI_TEST::SCOPED_TEMP_DIR & TempDir()
std::vector< std::string > ReadLines(const std::filesystem::path &aFile)
Read a text file into one string per line, with no trailing newline characters.
PAD_PROP
The set of pad properties used in Gerber files (Draw files, and P&P files) to define some properties ...
One LAYER block of matrix/matrix.
wxString m_dielectricType