20#include <magic_enum.hpp>
22#include <wx/tokenzr.h>
41#define LIB_VERSION_MAJOR 2
42#define LIB_VERSION_MINOR 4
44#define LIB_VERSION( major, minor ) ( major * 100 + minor )
47#define LIBFILE_IDENT "EESchema-LIBRARY Version"
50#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0"
58#define USE_OLD_DOC_FILE_FORMAT( major, minor ) \
59 ( LIB_VERSION( major, minor ) <= LIB_VERSION( 2, 4 ) )
81 wxString::Format(
"Cannot use relative file paths in legacy plugin to open library '%s'.",
91 const char* line = reader.
Line();
93 if( !
strCompare(
"EESchema-LIBRARY Version", line, &line ) )
97 if( !
strCompare(
"EESchema-LIB Version", line, &line ) )
98 SCH_PARSE_ERROR(
"file is not a valid symbol or symbol library file", reader, line );
114 SCH_PARSE_ERROR(
"invalid file version formatting in header", reader, line );
140 line = reader.
Line();
142 if( *line ==
'#' || isspace( *line ) )
181 if( !fn.FileExists() )
184 if( !fn.IsFileReadable() )
185 THROW_IO_ERRORF(
_(
"Insufficient permissions to read library '%s'." ), fn.GetFullPath() );
195 SCH_PARSE_ERROR(
"invalid document library file version formatting in header", reader, line );
199 line = reader.
Line();
207 aliasName = wxString::FromUTF8( line );
210 LIB_SYMBOL_MAP::iterator it =
m_symbols.find( aliasName );
215 "'%s'\n\nat line %d offset %d",
219 (
int) (line - reader.
Line() ) );
231 line = reader.
Line();
268 SCH_PARSE_ERROR(
"expected token in symbol definition", reader, line );
277 const char* line = aReader.
Line();
279 wxASSERT(
strCompare(
"$HEADER", line, &line ) );
283 line = (
char*) aReader;
289 else if(
strCompare(
"$ENDHEADER", line, &line ) )
300 const char* line = aReader.
Line();
302 while( *line ==
'#' )
310 wxString utf8Line = wxString::FromUTF8( line );
311 wxStringTokenizer tokens( utf8Line,
" \t\r\n" );
313 if( tokens.CountTokens() < 8 )
317 std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
319 wxString
name, prefix, tmp;
321 name = tokens.GetNextToken();
328 pos +=
name.size() + 1;
330 prefix = tokens.GetNextToken();
331 pos += prefix.size() + 1;
333 tmp = tokens.GetNextToken();
334 pos += tmp.size() + 1;
336 tmp = tokens.GetNextToken();
338 if( !tmp.ToLong( &num ) )
344 pos += tmp.size() + 1;
345 symbol->SetPinNameOffset(
schIUScale.MilsToIU( (
int)num ) );
347 tmp = tokens.GetNextToken();
349 if( !( tmp ==
"Y" || tmp ==
"N") )
355 pos += tmp.size() + 1;
356 symbol->SetShowPinNumbers( ( tmp ==
"N" ) ?
false :
true );
358 tmp = tokens.GetNextToken();
360 if( !( tmp ==
"Y" || tmp ==
"N") )
366 pos += tmp.size() + 1;
367 symbol->SetShowPinNames( ( tmp ==
"N" ) ?
false :
true );
369 tmp = tokens.GetNextToken();
371 if( !tmp.ToLong( &num ) )
374 pos += tmp.size() + 1;
375 symbol->SetUnitCount( (
int)num,
true );
378 if( symbol->GetUnitCount() < 1 )
379 symbol->SetUnitCount( 1,
true );
386 symbol->SetName(
"~" );
388 else if(
name[0] !=
'~' )
390 symbol->SetName(
name );
394 symbol->SetName(
name.Right(
name.Length() - 1 ) );
395 symbol->GetValueField().SetVisible(
false );
399 symbol->SetLibId(
LIB_ID( wxEmptyString, symbol->GetName() ) );
401 SCH_FIELD& reference = symbol->GetReferenceField();
415 if(
LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
420 tmp = tokens.GetNextToken();
421 pos += tmp.size() + 1;
425 tmp = tokens.GetNextToken();
428 symbol->LockUnits(
true );
429 else if( tmp ==
"F" || tmp ==
"0" )
430 symbol->LockUnits(
false );
435 pos += tmp.size() + 1;
439 if( tokens.HasMoreTokens() )
441 tmp = tokens.GetNextToken();
444 symbol->SetGlobalPower();
445 else if( tmp ==
"N" )
463 else if( *line ==
'F' )
467 else if(
strCompare(
"$FPLIST", line, &line ) )
469 else if(
strCompare(
"ENDDEF", line, &line ) )
471 symbol->SetHasDeMorganBodyStyles( symbol->HasLegacyAlternateBodyStyle() );
472 return symbol.release();
486 wxString newAliasName;
487 const char* line = aReader.
Line();
489 wxCHECK_RET(
strCompare(
"ALIAS", line, &line ),
"Invalid ALIAS section" );
491 wxString utf8Line = wxString::FromUTF8( line );
492 wxStringTokenizer tokens( utf8Line,
" \t\r\n" );
495 while( tokens.HasMoreTokens() )
497 newAliasName = tokens.GetNextToken();
507 SCH_FIELD* parentField = aSymbol->GetField( fieldId );
509 *field = *parentField;
512 field->
SetText( newAliasName );
521 (*aMap)[ newSymbol->
GetName() ] = newSymbol;
530 const char* line = aReader.
Line();
532 wxCHECK_RET( *line ==
'F',
"Invalid field line" );
537 if( sscanf( line + 1,
"%d", &legacy_field_id ) != 1 || legacy_field_id < 0 )
544 switch( legacy_field_id )
554 field = aSymbol->GetField(
id );
558 field =
new SCH_FIELD( aSymbol.get(),
id );
559 aSymbol->AddDrawItem( field,
false );
563 while( *line !=
'"' && *line != 0 )
578 if(
text.size() == 1 &&
text[0] ==
'~' )
579 field->
SetText( wxEmptyString );
594 char textOrient =
parseChar( aReader, line, &line );
596 if( textOrient ==
'H' )
598 else if( textOrient ==
'V' )
601 SCH_PARSE_ERROR(
"invalid field text orientation parameter", aReader, line );
603 char textVisible =
parseChar( aReader, line, &line );
605 if( textVisible ==
'V' )
607 else if ( textVisible ==
'I' )
610 SCH_PARSE_ERROR(
"invalid field text visibility parameter", aReader, line );
616 if( *line != 0 && *line !=
'"' )
618 char textHJustify =
parseChar( aReader, line, &line );
620 if( textHJustify ==
'C' )
622 else if( textHJustify ==
'L' )
624 else if( textHJustify ==
'R' )
627 SCH_PARSE_ERROR(
"invalid field text horizontal justification", aReader, line );
633 size_t attrSize = attributes.size();
635 if( !(attrSize == 3 || attrSize == 1 ) )
636 SCH_PARSE_ERROR(
"invalid field text attributes size", aReader, line );
638 switch( (wxChar) attributes[0] )
643 default:
SCH_PARSE_ERROR(
"invalid field text vertical justification", aReader, line );
648 wxChar attr_1 = attributes[1];
649 wxChar attr_2 = attributes[2];
653 else if( attr_1 !=
'N' )
654 SCH_PARSE_ERROR(
"invalid field text italic parameter", aReader, line );
658 else if( attr_2 !=
'N' )
674 field->
SetText( aSymbol->GetName() );
678 wxString fieldName = wxEmptyString;
681 if( fieldName.IsEmpty() )
684 wxString candidateFieldName = fieldName;
688 while( aSymbol->GetField( candidateFieldName ) !=
nullptr )
689 candidateFieldName = wxString::Format(
"%s_%d", fieldName, ++suffix );
691 field->
SetName( candidateFieldName );
701 const char* line = aReader.
Line();
703 wxCHECK_RET(
strCompare(
"DRAW", line, &line ),
"Invalid DRAW section" );
711 aSymbol->GetDrawItems().sort();
718 aSymbol->AddDrawItem(
loadArc( aReader ),
false );
722 aSymbol->AddDrawItem(
loadCircle( aReader ),
false );
726 aSymbol->AddDrawItem(
loadText( aReader, aMajorVersion, aMinorVersion ),
false );
730 aSymbol->AddDrawItem(
loadRect( aReader ),
false );
734 aSymbol->AddDrawItem(
loadPin( aSymbol, aReader ),
false );
742 aSymbol->AddDrawItem(
loadBezier( aReader ),
false );
758 SCH_PARSE_ERROR(
"File ended prematurely loading symbol draw element.", aReader, line );
763 const char** aOutput )
765 switch (
parseChar( aReader, aLine, aOutput ) )
773 SCH_PARSE_ERROR(
"invalid fill type, expected f, F, or N", aReader, aLine );
783 auto DECIDEG2RAD = [](
double deg ) ->
double
785 return deg *
M_PI / 1800.0;
792 delta = *aAngle2 - *aAngle1;
800 x = cos( DECIDEG2RAD( *aAngle1 ) );
801 y = -sin( DECIDEG2RAD( *aAngle1 ) );
804 x = cos( DECIDEG2RAD( *aAngle2 ) );
805 y = -sin( DECIDEG2RAD( *aAngle2 ) );
811 if( *aAngle2 < *aAngle1 )
814 if( *aAngle2 - *aAngle1 > 1800 )
816 angle = ( *aAngle1 );
817 *aAngle1 = ( *aAngle2 );
823 if( *aAngle2 < *aAngle1 )
841 const char* line = aReader.
Line();
843 wxCHECK_MSG(
strCompare(
"A", line, &line ),
nullptr,
"Invalid arc definition" );
855 int angle1 =
parseInt( aReader, line, &line );
856 int angle2 =
parseInt( aReader, line, &line );
928 const char* line = aReader.
Line();
930 wxCHECK_MSG(
strCompare(
"C", line, &line ),
nullptr,
"Invalid circle definition" );
949 circle->SetStroke( stroke );
959 int aMajorVersion,
int aMinorVersion )
961 const char* line = aReader.
Line();
963 wxCHECK_MSG(
strCompare(
"T", line, &line ),
nullptr,
"Invalid SCH_TEXT definition" );
965 double angleInTenths;
973 angleInTenths =
parseInt( aReader, line, &line );
978 visible = !
parseInt( aReader, line, &line );
979 unit =
parseInt( aReader, line, &line );
980 bodyStyle =
parseInt( aReader, line, &line );
994 str.Replace(
"~",
" " );
1000 str.Replace(
"''",
"\"" );
1015 sch_item = sch_text;
1016 eda_text = sch_text;
1033 if(
LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
1039 else if( !
strCompare(
"Normal", line, &line ) )
1040 SCH_PARSE_ERROR(
"invalid eda_text stype, expected 'Normal' or 'Italic'", aReader, line );
1042 if(
parseInt( aReader, line, &line ) > 0 )
1048 switch(
parseChar( aReader, line, &line ) )
1053 default:
SCH_PARSE_ERROR(
"invalid horizontal eda_text justication; expected L, C, or R",
1057 switch(
parseChar( aReader, line, &line ) )
1062 default:
SCH_PARSE_ERROR(
"invalid vertical eda_text justication; expected T, C, or B",
1074 const char* line = aReader.
Line();
1076 wxCHECK_MSG(
strCompare(
"S", line, &line ),
nullptr,
"Invalid rectangle definition" );
1111 const char* line = aReader.
Line();
1113 wxCHECK_MSG(
strCompare(
"X", line, &line ),
nullptr,
"Invalid SCH_PIN definition" );
1120 wxString utf8Line = wxString::FromUTF8( line );
1121 wxStringTokenizer tokens( utf8Line,
" \t\r\n" );
1123 if( tokens.CountTokens() < 11 )
1126 tmp = tokens.GetNextToken();
1128 pos += tmp.size() + 1;
1130 tmp = tokens.GetNextToken();
1132 pos += tmp.size() + 1;
1137 tmp = tokens.GetNextToken();
1139 if( !tmp.ToLong( &num ) )
1145 pos += tmp.size() + 1;
1148 tmp = tokens.GetNextToken();
1150 if( !tmp.ToLong( &num ) )
1156 pos += tmp.size() + 1;
1159 tmp = tokens.GetNextToken();
1161 if( !tmp.ToLong( &num ) )
1167 pos += tmp.size() + 1;
1168 int length =
schIUScale.MilsToIU( (
int) num );
1171 tmp = tokens.GetNextToken();
1173 if( tmp.size() > 1 )
1179 pos += tmp.size() + 1;
1183 switch(
static_cast<char>( tmp[0] ) )
1192 tmp = tokens.GetNextToken();
1194 if( !tmp.ToLong( &num ) )
1200 pos += tmp.size() + 1;
1201 int numberTextSize =
schIUScale.MilsToIU( (
int) num );
1203 tmp = tokens.GetNextToken();
1205 if( !tmp.ToLong( &num ) )
1211 pos += tmp.size() + 1;
1212 int nameTextSize =
schIUScale.MilsToIU( (
int) num );
1214 tmp = tokens.GetNextToken();
1216 if( !tmp.ToLong( &num ) )
1222 pos += tmp.size() + 1;
1223 int unit = (int) num;
1225 tmp = tokens.GetNextToken();
1227 if( !tmp.ToLong( &num ) )
1233 pos += tmp.size() + 1;
1234 int bodyStyle = (int) num;
1236 tmp = tokens.GetNextToken();
1238 if( tmp.size() != 1 )
1244 pos += tmp.size() + 1;
1279 if( tokens.HasMoreTokens() )
1281 tmp = tokens.GetNextToken();
1287 LOWLEVEL_IN = 1 << 2,
1288 LOWLEVEL_OUT = 1 << 3,
1289 FALLING_EDGE = 1 << 4,
1295 for(
int j = (
int) tmp.size(); j > 0; )
1297 switch( tmp[--j].GetValue() )
1300 case 'N':
pin->SetVisible(
false );
break;
1301 case 'I': flags |=
INVERTED;
break;
1302 case 'C': flags |=
CLOCK;
break;
1303 case 'L': flags |= LOWLEVEL_IN;
break;
1304 case 'V': flags |= LOWLEVEL_OUT;
break;
1305 case 'F': flags |= FALLING_EDGE;
break;
1306 case 'X': flags |=
NONLOGIC;
break;
1325 default:
SCH_PARSE_ERROR(
"pin attributes do not define a valid pin shape", aReader, line );
1335 const char* line = aReader.
Line();
1337 wxCHECK_MSG(
strCompare(
"P", line, &line ),
nullptr,
"Invalid poly definition" );
1341 int points =
parseInt( aReader, line, &line );
1351 for(
int i = 0; i < points; i++ )
1367 const char* line = aReader.
Line();
1369 wxCHECK_MSG(
strCompare(
"B", line, &line ),
nullptr,
"Invalid Bezier definition" );
1371 int points =
parseInt( aReader, line, &line );
1373 wxCHECK_MSG( points == 4, NULL,
"Invalid Bezier curve definition" );
1414 const char* line = aReader.
Line();
1416 wxCHECK_RET(
strCompare(
"$FPLIST", line, &line ),
"Invalid footprint filter list" );
1420 wxArrayString footprintFilters;
1424 if(
strCompare(
"$ENDFPLIST", line, &line ) )
1426 aSymbol->SetFPFilters( footprintFilters );
1433 footprintFilters.Add( footprint );
1437 SCH_PARSE_ERROR(
"File ended prematurely while loading footprint filters.", aReader, line );
1445 bool doSaveDocFile = *aOpt;
1453 auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
1455 formatter->Print( 0,
"#encoding utf-8\n");
1459 if( !it->second->IsRoot() )
1465 formatter->Print( 0,
"#\n#End Library\n" );
1466 formatter->Finish();
1486 wxCHECK_RET( aSymbol && aSymbol->
IsRoot(),
"Invalid LIB_SYMBOL pointer." );
1490 wxArrayString aliasNames;
1494 for(
auto& entry : *aMap )
1499 aliasNames.Add( symbol->
GetName() );
1509 aFormatter.
Print( 0,
"DEF" );
1514 if( !reference.
GetText().IsEmpty() )
1517 aFormatter.
Print( 0,
" ~" );
1519 aFormatter.
Print( 0,
" %d %d %c %c %d %c %c\n",
1528 if( dateModified != 0 )
1530 int sec = dateModified & 63;
1531 int min = ( dateModified >> 6 ) & 63;
1532 int hour = ( dateModified >> 12 ) & 31;
1533 int day = ( dateModified >> 17 ) & 31;
1534 int mon = ( dateModified >> 22 ) & 15;
1535 int year = ( dateModified >> 26 ) + 1990;
1537 aFormatter.
Print( 0,
"Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
1540 std::vector<SCH_FIELD*> orderedFields;
1544 int legacy_field_id = 0;
1547 saveField( field, legacy_field_id++, aFormatter );
1550 if( !aliasNames.IsEmpty() )
1552 aFormatter.
Print( 0,
"ALIAS" );
1554 for(
unsigned i = 0; i < aliasNames.GetCount(); i++ )
1555 aFormatter.
Print( 0,
" %s",
TO_UTF8( aliasNames[i] ) );
1557 aFormatter.
Print( 0,
"\n" );
1563 if( footprints.GetCount() != 0 )
1565 aFormatter.
Print( 0,
"$FPLIST\n" );
1567 for(
unsigned i = 0; i < footprints.GetCount(); i++ )
1568 aFormatter.
Print( 0,
" %s\n",
TO_UTF8( footprints[i] ) );
1570 aFormatter.
Print( 0,
"$ENDFPLIST\n" );
1579 aFormatter.
Print( 0,
"DRAW\n" );
1583 switch( item.Type() )
1615 aFormatter.
Print( 0,
"ENDDRAW\n" );
1618 aFormatter.
Print( 0,
"ENDDEF\n" );
1632 aFormatter.
Print( 0,
"A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
1653 aFormatter.
Print( 0,
"B 4 %d %d %d",
1658 aFormatter.
Print( 0,
" %d %d %d %d %d %d %d %d",
1676 aFormatter.
Print( 0,
"C %d %d %d %d %d %d %c\n",
1690 wxCHECK_RET( aField && aField->
Type() ==
SCH_FIELD_T,
"Invalid SCH_FIELD object." );
1692 int hjustify, vjustify;
1709 aFormatter.
Print( 0,
"F%d %s %d %d %d %c %c %c %c%c%c",
1719 aField->
IsBold() ?
'B' :
'N' );
1724 && !aField->
GetName().IsEmpty()
1730 aFormatter.
Print( 0,
"\n" );
1736 wxCHECK_RET( aPin && aPin->
Type() ==
SCH_PIN_T,
"Invalid SCH_PIN object." );
1756 if( !aPin->
GetName().IsEmpty() )
1759 aFormatter.
Print( 0,
"X ~" );
1761 int pin_orient =
'L';
1772 aFormatter.
Print( 0,
" %s %d %d %d %c %d %d %d %d %c",
1785 aFormatter.
Print( 0,
" " );
1788 aFormatter.
Print( 0,
"N" );
1801 default: wxFAIL_MSG(
"Invalid pin shape" );
1804 aFormatter.
Print( 0,
"\n" );
1815 aFormatter.
Print( 0,
"P %d %d %d %d",
1832 "Invalid RECT object." );
1834 aFormatter.
Print( 0,
"S %d %d %d %d %d %d %d %c\n",
1848 wxCHECK_RET( aText && aText->
Type() ==
SCH_TEXT_T,
"Invalid SCH_TEXT object." );
1852 if(
text.Contains( wxT(
" " ) ) ||
text.Contains( wxT(
"~" ) ) ||
text.Contains( wxT(
"\"" ) ) )
1855 text.Replace( wxT(
"\"" ), wxT(
"''" ) );
1856 text = wxT(
"\"" ) +
text + wxT(
"\"" );
1859 aFormatter.
Print( 0,
"T %d %d %d %d %d %d %d %s",
1869 aFormatter.
Print( 0,
" %s %d", aText->
IsItalic() ?
"Italic" :
"Normal", aText->
IsBold() );
1871 char hjustify =
'C';
1878 char vjustify =
'C';
1885 aFormatter.
Print( 0,
" %c %c\n", hjustify, vjustify );
1906 wxString description = it->second->GetDescription();
1907 wxString keyWords = it->second->GetKeyWords();
1908 wxString docFileName = it->second->GetDatasheetField().GetText();
1910 if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
1913 formatter.
Print( 0,
"#\n$CMP %s\n",
TO_UTF8( it->second->GetName() ) );
1915 if( !description.IsEmpty() )
1916 formatter.
Print( 0,
"D %s\n",
TO_UTF8( description ) );
1918 if( !keyWords.IsEmpty() )
1921 if( !docFileName.IsEmpty() )
1922 formatter.
Print( 0,
"F %s\n",
TO_UTF8( docFileName ) );
1924 formatter.
Print( 0,
"$ENDCMP\n" );
1927 formatter.
Print( 0,
"#\n#End Doc Library\n" );
1934 LIB_SYMBOL_MAP::iterator it =
m_symbols.find( aSymbolName );
1951 LIB_SYMBOL_MAP::iterator it1 =
m_symbols.begin();
1955 if( it1->second->IsDerived()
1956 && 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)
virtual void SetEnd(const VECTOR2I &aEnd)
const VECTOR2I & GetBezierC2() const
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.
virtual void SetBezierC2(const VECTOR2I &aPt)
virtual void SetBezierC1(const VECTOR2I &aPt)
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.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
const VECTOR2I & GetBezierC1() const
virtual int GetWidth() const
void SetFillMode(FILL_T aFill)
virtual void SetStart(const VECTOR2I &aStart)
VECTOR2I GetArcMid() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual VECTOR2I GetTextPos() const
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
virtual void SetTextPos(const VECTOR2I &aPoint)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual int GetTextWidth() const
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)
virtual EDA_ANGLE GetTextAngle() const
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.
std::weak_ptr< LIB_SYMBOL > & GetParent()
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...
std::shared_ptr< LIB_SYMBOL > SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
void SetHasDeMorganBodyStyles(bool aFlag)
bool IsGlobalPower() const override
int GetUnitCount() const override
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
virtual const wxString & GetText() const override
Return the string associated with the text object.
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)
wxFileName GetRealFile() const
long long GetLibModificationTime()
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_IO_ERRORF(msg,...)
#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.