29#include <wx/chartype.h>
55 return tented || covered ? 6 : 5;
59 return tented || covered ? 4 : 3;
64 return tented ? 1 : 0;
80 BOX2I holeBox = hole->BBox();
85 if( !footprint->GetBoundingBox(
false ).Intersects( holeBox ) )
88 for(
PAD*
pad : footprint->Pads() )
95 if( !aVia.
IsOnLayer( layer ) || !
pad->IsOnLayer( layer ) )
98 std::shared_ptr<SHAPE> copper =
pad->GetEffectiveShape( layer );
100 if( copper && copper->Collide( hole.get(), 0 ) )
125 for(
size_t ii = 0; ii < aStr.Len(); ++ii )
128 wxUniChar ch = aStr[ii];
130 if( ch > 126 || !std::isgraph(
static_cast<unsigned char>( ch ) ) )
145 wxUniChar character = aStr[aIndex];
146 unsigned int code = character.GetValue();
149 if( code >= 0xD800 && code <= 0xDBFF && aIndex + 1 < aStr.size() )
151 unsigned int next = aStr[aIndex + 1].GetValue();
153 if(
next >= 0xDC00 &&
next <= 0xDFFF )
164 out.reserve( aStr.size() );
166 for(
size_t ii = 0; ii < aStr.size(); ++ii )
169 unsigned int code = c.GetValue();
171 if( ( code >= 33 && code <= 126 ) && code !=
';' )
188 out.reserve( aStr.length() );
190 for(
size_t ii = 0; ii < aStr.Len(); ++ii )
195 if( code >= 33 && code <= 126 && code !=
';' )
197 out.append( 1,
static_cast<char>( code ) );
201 out.append( 1,
'_' );
215 out.reserve( aStr.size() );
217 for(
size_t ii = 0; ii < aStr.size(); ++ii )
222 if( code >=
'A' && code <=
'Z' )
223 character =
static_cast<char>( code -
'A' +
'a' );
224 else if( ( code >=
'a' && code <=
'z' ) || ( code >=
'0' && code <=
'9' ) || code ==
'-' || code ==
'_'
225 || code ==
'+' || code ==
'.' )
226 character =
static_cast<char>( code );
230 out.append( 1, character );
233 if( out.length() > 64 )
238 while( !out.IsEmpty() && ( out[0] ==
'.' || out[0] ==
'-' || out[0] ==
'+' ) )
243 while( !out.IsEmpty() && out.Last() ==
'.' )
252std::vector<wxString>
UniqueNames(
const std::vector<wxString>& aBases,
const std::set<wxString>& aReserved,
255 std::vector<wxString> bases;
256 bases.reserve( aBases.size() );
258 for(
const wxString& base : aBases )
260 wxCHECK_MSG( !base.IsEmpty(), aBases, wxS(
"ODB++ name base must not be empty" ) );
261 bases.push_back( base.Left( aMaxLength ) );
264 const std::set<wxString> originalBases( bases.begin(), bases.end() );
265 std::set<wxString> used = aReserved;
266 std::vector<wxString> names;
267 names.reserve( bases.size() );
270 std::map<wxString, size_t> nextSuffix;
272 for(
const wxString& base : bases )
274 wxString legal = base;
276 if( used.contains( legal ) )
278 size_t& suffixNumber = nextSuffix.try_emplace( base, 2 ).first->second;
280 for( ; ; ++suffixNumber )
282 wxString suffix = wxString::Format( wxS(
"_%zu" ), suffixNumber );
283 legal = base.Left( aMaxLength - suffix.length() ) + suffix;
285 if( !originalBases.contains( legal ) && !used.contains( legal ) )
290 names.push_back( legal );
291 used.insert( legal );
301 std::vector<wxString> bases;
302 std::vector<bool> unnamed;
303 bases.reserve( aNames.size() );
305 for(
const wxString&
name : aNames )
308 unnamed.push_back( base.IsEmpty() );
309 bases.push_back( base.IsEmpty() ? wxString( wxS(
"variant" ) ) : base );
312 std::vector<wxString> legalNames =
UniqueNames( bases, {}, 64 );
317 const wxString& base = bases[
index];
318 const wxString& legal = legalNames[
index];
320 if( unnamed[
index] || legal != base )
326 result.m_listsFit =
result.Join( aNames ).length() <= 1000;
335 if(
source.CmpNoCase( aName ) == 0 )
350 if(
source.CmpNoCase( aName ) == 0 )
362 for(
const wxString&
name : aNames )
376 aStr.Trim().Trim(
false );
377 wxRegEx spaces(
"\\s" );
378 spaces.Replace( &aStr,
"_" );
394 wxString str = wxString::FromCDouble( aVal, aDigits );
396 return str.ToStdString();
457 const wxString& aSubDir )
459 wxFileName
path = wxFileName::DirName( aPareDir );
461 wxArrayString subDirs = wxFileName::DirName( aSubDir.Lower() ).GetDirs();
463 for(
size_t i = 0; i < subDirs.GetCount(); i++ )
464 path.AppendDir( subDirs[i] );
466 if( !
path.DirExists() )
468 if( !
path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
470 throw( std::runtime_error(
"Could not create directory" +
path.GetPath() ) );
487 if( aFileName.IsEmpty() ||
m_treeWriter.GetCurrentPath().IsEmpty() )
492 fn.SetFullName( aFileName );
494 wxString dirPath = fn.GetPath();
496 if( !wxDir::Exists( dirPath ) )
498 if( !wxDir::Make( dirPath ) )
499 throw( std::runtime_error(
"Could not create directory" + dirPath ) );
502 if( !fn.IsDirWritable() || ( fn.Exists() && !fn.IsFileWritable() ) )
510 m_ostream.open( std::filesystem::path( std::wstring( fn.GetFullPath().wc_str() ) ),
511 std::ios_base::out | std::ios_base::trunc | std::ios_base::binary );
514 std::ios_base::out | std::ios_base::trunc | std::ios_base::binary );
517 m_ostream.imbue( std::locale::classic() );
520 throw std::runtime_error(
"Failed to open file: " + fn.GetFullPath() );
531 throw std::runtime_error(
"close file failed" );
541 m_ostream << var <<
"=" << value << std::endl;
548 m_ostream << var <<
"=" << value << std::endl;
562 throw std::runtime_error(
"already in array" );
571 throw std::runtime_error(
"not in array" );
573 m_ostream <<
"}" << std::endl << std::endl;
591 const wxString& aUserParams ) :
598 const wxString& aType2 )
606 if( existing.m_type == aType && existing.m_type2 == aType2
607 && existing.m_drillSize == size )
632 for(
const auto& tool :
m_tools )
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Information pertinent to a Pcbnew printed circuit board.
const FOOTPRINTS & Footprints() const
int GetRectangleWidth() const
int GetRectangleHeight() const
ODB_TREE_WRITER & m_treeWriter
ODB_FILE_WRITER(ODB_TREE_WRITER &aTreeWriter, const wxString &aFileName)
void CreateODBFile(const wxString &aFileName)
ARRAY_PROXY(ODB_TEXT_WRITER &aWriter, const std::string &aStr)
ODB_TEXT_WRITER & m_writer
void WriteEquationLine(const std::string &var, int value)
ARRAY_PROXY MakeArrayProxy(const std::string &aStr)
void BeginArray(const std::string &a)
void CreateEntityDirectory(const wxString &aPareDir, const wxString &aSubDir=wxEmptyString)
VECTOR2I GetPosition() const override
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
wxString GenLegalComponentName(const wxString &aStr)
std::vector< ODB_TYPE > OverridableLayerTypes(PCB_LAYER_ID aLayer)
Matrix types a layer override may assign to aLayer.
std::pair< wxString, wxString > AddXY(const ODB_FORMAT &aFormat, const VECTOR2I &aVec)
void RemoveWhitespace(wxString &aStr)
std::vector< wxString > UniqueNames(const std::vector< wxString > &aBases, const std::set< wxString > &aReserved, size_t aMaxLength)
wxString GenODBString(const wxString &aStr)
wxString Data2String(const ODB_FORMAT &aFormat, double aVal)
int IpcViaType(const DRILL_OPERATION &aOperation, bool aTop)
std::pair< wxString, wxString > AddRelativeXY(const ODB_FORMAT &aFormat, const VECTOR2I &aVec)
wxString GenLegalEntityName(const wxString &aStr)
wxString GenLegalNetName(const wxString &aStr)
bool ViaInPad(const PCB_VIA &aVia)
static wxUniChar NextCharacter(const wxString &aStr, size_t &aIndex)
VECTOR2I GetShapePosition(const PCB_SHAPE &aShape)
wxString SymDouble2String(const ODB_FORMAT &aFormat, double aVal)
wxString Double2String(const ODB_FORMAT &aFormat, double aVal)
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
wxString FormatTrimmedDecimal(double aValue, int aPrecision)
Format a value to aPrecision decimal digits and strip trailing zeros, keeping one digit after the dec...
One machining action, which is also one NC hit and one tool assignment.
std::vector< std::pair< wxString, wxString > > m_names
wxString Join(const std::vector< wxString > &aNames) const
wxString LegalName(const wxString &aName) const
wxString SelectedName(const wxString &aName) const
static VARIANT_NAMES Build(const std::vector< wxString > &aNames)
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D