20#include <magic_enum.hpp>
38#define LIB_VERSION_MAJOR 2
39#define LIB_VERSION_MINOR 4
41#define LIB_VERSION( major, minor ) ( major * 100 + minor )
44#define LIBFILE_IDENT "EESchema-LIBRARY Version"
47#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0"
55#define USE_OLD_DOC_FILE_FORMAT( major, minor ) \
56 ( LIB_VERSION( major, minor ) <= LIB_VERSION( 2, 4 ) )
79 wxString::Format(
"Cannot use relative file paths in legacy plugin to "
90 const char* line = reader.
Line();
92 if( !
strCompare(
"EESchema-LIBRARY Version", line, &line ) )
96 if( !
strCompare(
"EESchema-LIB Version", line, &line ) )
97 SCH_PARSE_ERROR(
"file is not a valid symbol or symbol library file", reader, line );
113 SCH_PARSE_ERROR(
"invalid file version formatting in header", reader, line );
139 line = reader.
Line();
141 if( *line ==
'#' || isspace( *line ) )
180 if( !fn.FileExists() )
183 if( !fn.IsFileReadable() )
185 THROW_IO_ERROR( wxString::Format(
_(
"Insufficient permissions to read library '%s'." ),
186 fn.GetFullPath() ) );
197 SCH_PARSE_ERROR(
"invalid document library file version formatting in header", reader, line );
201 line = reader.
Line();
209 aliasName = wxString::FromUTF8( line );
212 LIB_SYMBOL_MAP::iterator it =
m_symbols.find( aliasName );
216 wxLogWarning(
"Symbol '%s' not found in library:\n\n"
217 "'%s'\n\nat line %d offset %d",
221 (
int) (line - reader.
Line() ) );
233 line = reader.
Line();
270 SCH_PARSE_ERROR(
"expected token in symbol definition", reader, line );
279 const char* line = aReader.
Line();
281 wxASSERT(
strCompare(
"$HEADER", line, &line ) );
285 line = (
char*) aReader;
291 else if(
strCompare(
"$ENDHEADER", line, &line ) )
302 const char* line = aReader.
Line();
304 while( *line ==
'#' )
312 wxString utf8Line = wxString::FromUTF8( line );
313 wxStringTokenizer tokens( utf8Line,
" \t\r\n" );
315 if( tokens.CountTokens() < 8 )
319 std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
321 wxString
name, prefix, tmp;
323 name = tokens.GetNextToken();
330 pos +=
name.size() + 1;
332 prefix = tokens.GetNextToken();
333 pos += prefix.size() + 1;
335 tmp = tokens.GetNextToken();
336 pos += tmp.size() + 1;
338 tmp = tokens.GetNextToken();
340 if( !tmp.ToLong( &num ) )
346 pos += tmp.size() + 1;
347 symbol->SetPinNameOffset(
schIUScale.MilsToIU( (
int)num ) );
349 tmp = tokens.GetNextToken();
351 if( !( tmp ==
"Y" || tmp ==
"N") )
357 pos += tmp.size() + 1;
358 symbol->SetShowPinNumbers( ( tmp ==
"N" ) ?
false :
true );
360 tmp = tokens.GetNextToken();
362 if( !( tmp ==
"Y" || tmp ==
"N") )
368 pos += tmp.size() + 1;
369 symbol->SetShowPinNames( ( tmp ==
"N" ) ?
false :
true );
371 tmp = tokens.GetNextToken();
373 if( !tmp.ToLong( &num ) )
376 pos += tmp.size() + 1;
377 symbol->SetUnitCount( (
int)num,
true );
380 if( symbol->GetUnitCount() < 1 )
381 symbol->SetUnitCount( 1,
true );
388 symbol->SetName(
"~" );
390 else if(
name[0] !=
'~' )
392 symbol->SetName(
name );
396 symbol->SetName(
name.Right(
name.Length() - 1 ) );
397 symbol->GetValueField().SetVisible(
false );
401 symbol->SetLibId(
LIB_ID( wxEmptyString, symbol->GetName() ) );
403 SCH_FIELD& reference = symbol->GetReferenceField();
417 if(
LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
422 tmp = tokens.GetNextToken();
423 pos += tmp.size() + 1;
427 tmp = tokens.GetNextToken();
430 symbol->LockUnits(
true );
431 else if( tmp ==
"F" || tmp ==
"0" )
432 symbol->LockUnits(
false );
437 pos += tmp.size() + 1;
441 if( tokens.HasMoreTokens() )
443 tmp = tokens.GetNextToken();
446 symbol->SetGlobalPower();
447 else if( tmp ==
"N" )
465 else if( *line ==
'F' )
469 else if(
strCompare(
"$FPLIST", line, &line ) )
471 else if(
strCompare(
"ENDDEF", line, &line ) )
473 symbol->SetHasDeMorganBodyStyles( symbol->HasLegacyAlternateBodyStyle() );
474 return symbol.release();
488 wxString newAliasName;
489 const char* line = aReader.
Line();
491 wxCHECK_RET(
strCompare(
"ALIAS", line, &line ),
"Invalid ALIAS section" );
493 wxString utf8Line = wxString::FromUTF8( line );
494 wxStringTokenizer tokens( utf8Line,
" \t\r\n" );
497 while( tokens.HasMoreTokens() )
499 newAliasName = tokens.GetNextToken();
509 SCH_FIELD* parentField = aSymbol->GetField( fieldId );
511 *field = *parentField;
514 field->
SetText( newAliasName );
523 (*aMap)[ newSymbol->
GetName() ] = newSymbol;
532 const char* line = aReader.
Line();
534 wxCHECK_RET( *line ==
'F',
"Invalid field line" );
539 if( sscanf( line + 1,
"%d", &legacy_field_id ) != 1 || legacy_field_id < 0 )
546 switch( legacy_field_id )
556 field = aSymbol->GetField(
id );
560 field =
new SCH_FIELD( aSymbol.get(),
id );
561 aSymbol->AddDrawItem( field,
false );
565 while( *line !=
'"' && *line != 0 )
580 if(
text.size() == 1 &&
text[0] ==
'~' )
581 field->
SetText( wxEmptyString );
596 char textOrient =
parseChar( aReader, line, &line );
598 if( textOrient ==
'H' )
600 else if( textOrient ==
'V' )
603 SCH_PARSE_ERROR(
"invalid field text orientation parameter", aReader, line );
605 char textVisible =
parseChar( aReader, line, &line );
607 if( textVisible ==
'V' )
609 else if ( textVisible ==
'I' )
612 SCH_PARSE_ERROR(
"invalid field text visibility parameter", aReader, line );
618 if( *line != 0 && *line !=
'"' )
620 char textHJustify =
parseChar( aReader, line, &line );
622 if( textHJustify ==
'C' )
624 else if( textHJustify ==
'L' )
626 else if( textHJustify ==
'R' )
629 SCH_PARSE_ERROR(
"invalid field text horizontal justification", aReader, line );
635 size_t attrSize = attributes.size();
637 if( !(attrSize == 3 || attrSize == 1 ) )
638 SCH_PARSE_ERROR(
"invalid field text attributes size", aReader, line );
640 switch( (wxChar) attributes[0] )
645 default:
SCH_PARSE_ERROR(
"invalid field text vertical justification", aReader, line );
650 wxChar attr_1 = attributes[1];
651 wxChar attr_2 = attributes[2];
655 else if( attr_1 !=
'N' )
656 SCH_PARSE_ERROR(
"invalid field text italic parameter", aReader, line );
660 else if( attr_2 !=
'N' )
676 field->
SetText( aSymbol->GetName() );
680 wxString fieldName = wxEmptyString;
683 if( fieldName.IsEmpty() )
686 wxString candidateFieldName = fieldName;
690 while( aSymbol->GetField( candidateFieldName ) !=
nullptr )
691 candidateFieldName = wxString::Format(
"%s_%d", fieldName, ++suffix );
693 field->
SetName( candidateFieldName );
703 const char* line = aReader.
Line();
705 wxCHECK_RET(
strCompare(
"DRAW", line, &line ),
"Invalid DRAW section" );
713 aSymbol->GetDrawItems().sort();
720 aSymbol->AddDrawItem(
loadArc( aReader ),
false );
724 aSymbol->AddDrawItem(
loadCircle( aReader ),
false );
728 aSymbol->AddDrawItem(
loadText( aReader, aMajorVersion, aMinorVersion ),
false );
732 aSymbol->AddDrawItem(
loadRect( aReader ),
false );
736 aSymbol->AddDrawItem(
loadPin( aSymbol, aReader ),
false );
744 aSymbol->AddDrawItem(
loadBezier( aReader ),
false );
760 SCH_PARSE_ERROR(
"File ended prematurely loading symbol draw element.", aReader, line );
765 const char** aOutput )
767 switch (
parseChar( aReader, aLine, aOutput ) )
775 SCH_PARSE_ERROR(
"invalid fill type, expected f, F, or N", aReader, aLine );
785 auto DECIDEG2RAD = [](
double deg ) ->
double
787 return deg *
M_PI / 1800.0;
794 delta = *aAngle2 - *aAngle1;
802 x = cos( DECIDEG2RAD( *aAngle1 ) );
803 y = -sin( DECIDEG2RAD( *aAngle1 ) );
806 x = cos( DECIDEG2RAD( *aAngle2 ) );
807 y = -sin( DECIDEG2RAD( *aAngle2 ) );
813 if( *aAngle2 < *aAngle1 )
816 if( *aAngle2 - *aAngle1 > 1800 )
818 angle = ( *aAngle1 );
819 *aAngle1 = ( *aAngle2 );
825 if( *aAngle2 < *aAngle1 )
843 const char* line = aReader.
Line();
845 wxCHECK_MSG(
strCompare(
"A", line, &line ),
nullptr,
"Invalid arc definition" );
857 int angle1 =
parseInt( aReader, line, &line );
858 int angle2 =
parseInt( aReader, line, &line );
924 const char* line = aReader.
Line();
926 wxCHECK_MSG(
strCompare(
"C", line, &line ),
nullptr,
"Invalid circle definition" );
945 circle->SetStroke( stroke );
955 int aMajorVersion,
int aMinorVersion )
957 const char* line = aReader.
Line();
959 wxCHECK_MSG(
strCompare(
"T", line, &line ),
nullptr,
"Invalid SCH_TEXT definition" );
961 double angleInTenths;
969 angleInTenths =
parseInt( aReader, line, &line );
974 visible = !
parseInt( aReader, line, &line );
975 unit =
parseInt( aReader, line, &line );
976 bodyStyle =
parseInt( aReader, line, &line );
990 str.Replace(
"~",
" " );
996 str.Replace(
"''",
"\"" );
1011 sch_item = sch_text;
1012 eda_text = sch_text;
1029 if(
LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
1035 else if( !
strCompare(
"Normal", line, &line ) )
1036 SCH_PARSE_ERROR(
"invalid eda_text stype, expected 'Normal' or 'Italic'", aReader, line );
1038 if(
parseInt( aReader, line, &line ) > 0 )
1044 switch(
parseChar( aReader, line, &line ) )
1049 default:
SCH_PARSE_ERROR(
"invalid horizontal eda_text justication; expected L, C, or R",
1053 switch(
parseChar( aReader, line, &line ) )
1058 default:
SCH_PARSE_ERROR(
"invalid vertical eda_text justication; expected T, C, or B",
1070 const char* line = aReader.
Line();
1072 wxCHECK_MSG(
strCompare(
"S", line, &line ),
nullptr,
"Invalid rectangle definition" );
1107 const char* line = aReader.
Line();
1109 wxCHECK_MSG(
strCompare(
"X", line, &line ),
nullptr,
"Invalid SCH_PIN definition" );
1116 wxString utf8Line = wxString::FromUTF8( line );
1117 wxStringTokenizer tokens( utf8Line,
" \t\r\n" );
1119 if( tokens.CountTokens() < 11 )
1122 tmp = tokens.GetNextToken();
1124 pos += tmp.size() + 1;
1126 tmp = tokens.GetNextToken();
1128 pos += tmp.size() + 1;
1133 tmp = tokens.GetNextToken();
1135 if( !tmp.ToLong( &num ) )
1141 pos += tmp.size() + 1;
1144 tmp = tokens.GetNextToken();
1146 if( !tmp.ToLong( &num ) )
1152 pos += tmp.size() + 1;
1155 tmp = tokens.GetNextToken();
1157 if( !tmp.ToLong( &num ) )
1163 pos += tmp.size() + 1;
1164 int length =
schIUScale.MilsToIU( (
int) num );
1167 tmp = tokens.GetNextToken();
1169 if( tmp.size() > 1 )
1175 pos += tmp.size() + 1;
1179 switch(
static_cast<char>( tmp[0] ) )
1188 tmp = tokens.GetNextToken();
1190 if( !tmp.ToLong( &num ) )
1196 pos += tmp.size() + 1;
1197 int numberTextSize =
schIUScale.MilsToIU( (
int) num );
1199 tmp = tokens.GetNextToken();
1201 if( !tmp.ToLong( &num ) )
1207 pos += tmp.size() + 1;
1208 int nameTextSize =
schIUScale.MilsToIU( (
int) num );
1210 tmp = tokens.GetNextToken();
1212 if( !tmp.ToLong( &num ) )
1218 pos += tmp.size() + 1;
1219 int unit = (int) num;
1221 tmp = tokens.GetNextToken();
1223 if( !tmp.ToLong( &num ) )
1229 pos += tmp.size() + 1;
1230 int bodyStyle = (int) num;
1232 tmp = tokens.GetNextToken();
1234 if( tmp.size() != 1 )
1240 pos += tmp.size() + 1;
1275 if( tokens.HasMoreTokens() )
1277 tmp = tokens.GetNextToken();
1283 LOWLEVEL_IN = 1 << 2,
1284 LOWLEVEL_OUT = 1 << 3,
1285 FALLING_EDGE = 1 << 4,
1291 for(
int j = (
int) tmp.size(); j > 0; )
1293 switch( tmp[--j].GetValue() )
1296 case 'N':
pin->SetVisible(
false );
break;
1297 case 'I': flags |=
INVERTED;
break;
1298 case 'C': flags |=
CLOCK;
break;
1299 case 'L': flags |= LOWLEVEL_IN;
break;
1300 case 'V': flags |= LOWLEVEL_OUT;
break;
1301 case 'F': flags |= FALLING_EDGE;
break;
1302 case 'X': flags |=
NONLOGIC;
break;
1321 default:
SCH_PARSE_ERROR(
"pin attributes do not define a valid pin shape", aReader, line );
1331 const char* line = aReader.
Line();
1333 wxCHECK_MSG(
strCompare(
"P", line, &line ),
nullptr,
"Invalid poly definition" );
1337 int points =
parseInt( aReader, line, &line );
1347 for(
int i = 0; i < points; i++ )
1363 const char* line = aReader.
Line();
1365 wxCHECK_MSG(
strCompare(
"B", line, &line ),
nullptr,
"Invalid Bezier definition" );
1367 int points =
parseInt( aReader, line, &line );
1369 wxCHECK_MSG( points == 4, NULL,
"Invalid Bezier curve definition" );
1410 const char* line = aReader.
Line();
1412 wxCHECK_RET(
strCompare(
"$FPLIST", line, &line ),
"Invalid footprint filter list" );
1416 wxArrayString footprintFilters;
1420 if(
strCompare(
"$ENDFPLIST", line, &line ) )
1422 aSymbol->SetFPFilters( footprintFilters );
1429 footprintFilters.Add( footprint );
1433 SCH_PARSE_ERROR(
"File ended prematurely while loading footprint filters.", aReader, line );
1441 bool doSaveDocFile = *aOpt;
1449 auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
1451 formatter->Print( 0,
"#encoding utf-8\n");
1455 if( !it->second->IsRoot() )
1461 formatter->Print( 0,
"#\n#End Library\n" );
1481 wxCHECK_RET( aSymbol && aSymbol->
IsRoot(),
"Invalid LIB_SYMBOL pointer." );
1485 wxArrayString aliasNames;
1489 for(
auto& entry : *aMap )
1494 aliasNames.Add( symbol->
GetName() );
1504 aFormatter.
Print( 0,
"DEF" );
1509 if( !reference.
GetText().IsEmpty() )
1512 aFormatter.
Print( 0,
" ~" );
1514 aFormatter.
Print( 0,
" %d %d %c %c %d %c %c\n",
1523 if( dateModified != 0 )
1525 int sec = dateModified & 63;
1526 int min = ( dateModified >> 6 ) & 63;
1527 int hour = ( dateModified >> 12 ) & 31;
1528 int day = ( dateModified >> 17 ) & 31;
1529 int mon = ( dateModified >> 22 ) & 15;
1530 int year = ( dateModified >> 26 ) + 1990;
1532 aFormatter.
Print( 0,
"Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
1535 std::vector<SCH_FIELD*> orderedFields;
1539 int legacy_field_id = 0;
1542 saveField( field, legacy_field_id++, aFormatter );
1545 if( !aliasNames.IsEmpty() )
1547 aFormatter.
Print( 0,
"ALIAS" );
1549 for(
unsigned i = 0; i < aliasNames.GetCount(); i++ )
1550 aFormatter.
Print( 0,
" %s",
TO_UTF8( aliasNames[i] ) );
1552 aFormatter.
Print( 0,
"\n" );
1558 if( footprints.GetCount() != 0 )
1560 aFormatter.
Print( 0,
"$FPLIST\n" );
1562 for(
unsigned i = 0; i < footprints.GetCount(); i++ )
1563 aFormatter.
Print( 0,
" %s\n",
TO_UTF8( footprints[i] ) );
1565 aFormatter.
Print( 0,
"$ENDFPLIST\n" );
1574 aFormatter.
Print( 0,
"DRAW\n" );
1578 switch( item.Type() )
1610 aFormatter.
Print( 0,
"ENDDRAW\n" );
1613 aFormatter.
Print( 0,
"ENDDEF\n" );
1627 aFormatter.
Print( 0,
"A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
1648 aFormatter.
Print( 0,
"B 4 %d %d %d",
1653 aFormatter.
Print( 0,
" %d %d %d %d %d %d %d %d",
1671 aFormatter.
Print( 0,
"C %d %d %d %d %d %d %c\n",
1685 wxCHECK_RET( aField && aField->
Type() ==
SCH_FIELD_T,
"Invalid SCH_FIELD object." );
1687 int hjustify, vjustify;
1704 aFormatter.
Print( 0,
"F%d %s %d %d %d %c %c %c %c%c%c",
1714 aField->
IsBold() ?
'B' :
'N' );
1719 && !aField->
GetName().IsEmpty()
1725 aFormatter.
Print( 0,
"\n" );
1731 wxCHECK_RET( aPin && aPin->
Type() ==
SCH_PIN_T,
"Invalid SCH_PIN object." );
1751 if( !aPin->
GetName().IsEmpty() )
1754 aFormatter.
Print( 0,
"X ~" );
1756 int pin_orient =
'L';
1767 aFormatter.
Print( 0,
" %s %d %d %d %c %d %d %d %d %c",
1780 aFormatter.
Print( 0,
" " );
1783 aFormatter.
Print( 0,
"N" );
1796 default: wxFAIL_MSG(
"Invalid pin shape" );
1799 aFormatter.
Print( 0,
"\n" );
1810 aFormatter.
Print( 0,
"P %d %d %d %d",
1827 "Invalid RECT object." );
1829 aFormatter.
Print( 0,
"S %d %d %d %d %d %d %d %c\n",
1843 wxCHECK_RET( aText && aText->
Type() ==
SCH_TEXT_T,
"Invalid SCH_TEXT object." );
1847 if(
text.Contains( wxT(
" " ) ) ||
text.Contains( wxT(
"~" ) ) ||
text.Contains( wxT(
"\"" ) ) )
1850 text.Replace( wxT(
"\"" ), wxT(
"''" ) );
1851 text = wxT(
"\"" ) +
text + wxT(
"\"" );
1854 aFormatter.
Print( 0,
"T %d %d %d %d %d %d %d %s",
1864 aFormatter.
Print( 0,
" %s %d", aText->
IsItalic() ?
"Italic" :
"Normal", aText->
IsBold() );
1866 char hjustify =
'C';
1873 char vjustify =
'C';
1880 aFormatter.
Print( 0,
" %c %c\n", hjustify, vjustify );
1901 wxString description = it->second->GetDescription();
1902 wxString keyWords = it->second->GetKeyWords();
1903 wxString docFileName = it->second->GetDatasheetField().GetText();
1905 if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
1908 formatter.
Print( 0,
"#\n$CMP %s\n",
TO_UTF8( it->second->GetName() ) );
1910 if( !description.IsEmpty() )
1911 formatter.
Print( 0,
"D %s\n",
TO_UTF8( description ) );
1913 if( !keyWords.IsEmpty() )
1916 if( !docFileName.IsEmpty() )
1917 formatter.
Print( 0,
"F %s\n",
TO_UTF8( docFileName ) );
1919 formatter.
Print( 0,
"$ENDCMP\n" );
1922 formatter.
Print( 0,
"#\n#End Doc Library\n" );
1928 LIB_SYMBOL_MAP::iterator it =
m_symbols.find( aSymbolName );
1931 THROW_IO_ERROR( wxString::Format(
_(
"library %s does not contain a symbol named %s" ),
1943 LIB_SYMBOL_MAP::iterator it1 =
m_symbols.begin();
1947 if( it1->second->IsDerived()
1948 && it1->second->GetParent().lock() == rootSymbol->
SharedPtr() )
constexpr EDA_IU_SCALE schIUScale
constexpr double ARC_LOW_DEF_MM
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
int AsTenthsOfADegree() const
bool IsHorizontal() const
KICAD_T Type() const
Returns the type of object.
virtual void SetParent(EDA_ITEM *aParent)
const VECTOR2I & GetBezierC2() const
void SetBezierC2(const VECTOR2I &aPt)
FILL_T GetFillMode() const
SHAPE_POLY_SET & GetPolyShape()
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetEnd(const VECTOR2I &aEnd)
void SetBezierC1(const VECTOR2I &aPt)
const VECTOR2I & GetBezierC1() const
virtual int GetWidth() const
void SetFillMode(FILL_T aFill)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
const VECTOR2I & GetTextPos() const
const EDA_ANGLE & GetTextAngle() const
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
void SetTextPos(const VECTOR2I &aPoint)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
void SetBoldFlag(bool aBold)
Set only the bold flag, without changing the font.
virtual void SetVisible(bool aVisible)
void SetItalicFlag(bool aItalic)
Set only the italic flag, without changing the font.
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
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.
A logical library item identifier and consists of various portions much like a URI.
Define a library symbol object.
void GetFields(std::vector< SCH_FIELD * > &aList, bool aVisibleOnly=false) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
bool UnitsLocked() const
Check whether symbol units are interchangeable.
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
timestamp_t GetLastModDate() const
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
void SetParent(LIB_SYMBOL *aParent=nullptr)
wxString GetName() const override
void SetDescription(const wxString &aDescription)
Gets the Description field text value */.
void SetKeyWords(const wxString &aKeyWords)
SCH_FIELD & GetValueField()
Return reference to the value field.
wxArrayString GetFPFilters() const
bool HasLegacyAlternateBodyStyle() const
Before V10 we didn't store the number of body styles in a symbol – we just looked through all its dra...
void SetHasDeMorganBodyStyles(bool aFlag)
LIB_SYMBOL_SPTR SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
bool IsGlobalPower() const override
int GetUnitCount() const override
LIB_SYMBOL_REF & GetParent()
SCH_FIELD & GetReferenceField()
Return reference to the reference designator field.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
char * Line() const
Return a pointer to the last line that was read in.
bool empty(int aType=UNDEFINED_TYPE) const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetPosition(const VECTOR2I &aPosition) override
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
SCH_IO_KICAD_LEGACY_LIB_CACHE(const wxString &aLibraryPath)
static void loadDrawEntries(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
void loadHeader(FILE_LINE_READER &aReader)
static SCH_SHAPE * loadBezier(LINE_READER &aReader)
static void saveField(const SCH_FIELD *aField, int aLegacyFieldIdx, OUTPUTFORMATTER &aFormatter)
static void saveArc(SCH_SHAPE *aArc, OUTPUTFORMATTER &aFormatter)
static void saveCircle(SCH_SHAPE *aCircle, OUTPUTFORMATTER &aFormatter)
static SCH_SHAPE * loadArc(LINE_READER &aReader)
static void loadField(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
static LIB_SYMBOL * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_SYMBOL_MAP *aMap=nullptr)
static void savePolyLine(SCH_SHAPE *aPolyLine, OUTPUTFORMATTER &aFormatter)
static SCH_SHAPE * loadPolyLine(LINE_READER &aReader)
static void saveBezier(SCH_SHAPE *aBezier, OUTPUTFORMATTER &aFormatter)
static SCH_SHAPE * loadCircle(LINE_READER &aReader)
static SCH_ITEM * loadText(LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
void Save(const std::optional< bool > &aOpt) override
Save the entire library to file m_libFileName;.
static SCH_SHAPE * loadRect(LINE_READER &aReader)
static void loadAliases(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, LIB_SYMBOL_MAP *aMap=nullptr)
static void loadFootprintFilters(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
void DeleteSymbol(const wxString &aName) override
static void savePin(const SCH_PIN *aPin, OUTPUTFORMATTER &aFormatter)
static SCH_PIN * loadPin(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static void saveRectangle(SCH_SHAPE *aRectangle, OUTPUTFORMATTER &aFormatter)
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)
static void saveText(const SCH_TEXT *aText, OUTPUTFORMATTER &aFormatter)
wxDateTime GetLibModificationTime()
wxFileName GetRealFile() const
SCH_IO_LIB_CACHE(const wxString &aLibraryPath)
void IncrementModifyHash()
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual void SetBodyStyle(int aBodyStyle)
virtual void SetUnit(int aUnit)
int GetNumberTextSize() const
const wxString & GetName() const
PIN_ORIENTATION GetOrientation() const
VECTOR2I GetPosition() const override
int GetNameTextSize() const
const wxString & GetNumber() const
GRAPHIC_PINSHAPE GetShape() const
ELECTRICAL_PINTYPE GetType() const
void SetPosition(const VECTOR2I &aPos) override
void SetStroke(const STROKE_PARAMS &aStroke) override
VECTOR2I GetCenter() const
void AddPoint(const VECTOR2I &aPosition)
VECTOR2I GetPosition() const override
virtual size_t GetPointCount() const override
const std::vector< VECTOR2I > & CPoints() const
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
Simple container to manage line stroke parameters.
int GetPinNameOffset() const
virtual bool GetShowPinNames() const
virtual bool GetShowPinNumbers() const
static constexpr EDA_ANGLE ANGLE_VERTICAL
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
#define IS_CHANGED
Item was edited, and modified.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ FILLED_WITH_BG_BODYCOLOR
@ FILLED_SHAPE
Fill with object color.
static const std::string LegacySymbolDocumentFileExtension
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
std::chrono::steady_clock CLOCK
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
This file contains miscellaneous commonly used macros and functions.
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
@ PT_INPUT
usual pin input: must be connected
@ PT_NC
not connected (must be left open)
@ PT_TRISTATE
tri state bus pin
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_OPENEMITTER
pin type open emitter
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
@ PT_OPENCOLLECTOR
pin type open collector
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
PIN_ORIENTATION
The symbol library pin object orientations.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
bool strCompare(const char *aString, const char *aLine, const char **aOutput)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define SCH_PARSE_ERROR(text, reader, pos)
static bool MapAnglesV6(int *aAngle1, int *aAngle2)
This function based on version 6.0 is required for reading legacy arcs.
#define LIB_VERSION_MINOR
Legacy symbol library minor version.
#define LIBFILE_IDENT
Legacy symbol library (.lib) file header.
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
Library versions 2.4 and lower use the old separate library (.lib) and document (....
#define LIB_VERSION(major, minor)
#define DOCFILE_IDENT
Legacy symbol library document (.dcm) file header.
#define LIB_VERSION_MAJOR
Legacy symbol library major version.
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
wxString UnescapeString(const wxString &aSource)
wxString From_UTF8(const char *cstring)
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
wxString GetCanonicalFieldName(FIELD_T aFieldType)
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
wxLogTrace helper definitions.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
void NORMALIZE_ANGLE_POS(T &Angle)
double RAD2DECIDEG(double rad)
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.