24#include <boost/algorithm/string/join.hpp>
29#include <wx/mstream.h>
30#include <wx/filename.h>
32#include <wx/textfile.h>
33#include <wx/tokenzr.h>
69#define T_STYLE "style"
71#define T_COLORA "rgba"
72#define T_WIDTH "width"
77 m_progressReporter( nullptr ),
78 m_lineReader( nullptr ),
79 m_lastProgressLine( 0 ),
105 const unsigned PROGRESS_DELTA = 250;
129 wxASSERT( !aFileName || aSchematic !=
nullptr );
134 wxFileName fn = aFileName;
139 wxASSERT( fn.IsAbsolute() );
148 if( !normedFn.IsAbsolute() )
150 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
151 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
165 init( aSchematic, aProperties );
167 if( aAppendToMe ==
nullptr )
170 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
171 newSheet->SetFileName( aFileName );
176 sheet = newSheet.release();
182 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
208 fileName.SetExt(
"sch" );
210 if( !fileName.IsAbsolute() )
259 wxCHECK2( aItem->Type() ==
SCH_SHEET_T,
continue );
260 auto sheet =
static_cast<SCH_SHEET*
>( aItem );
308 char* line = reader.
Line();
310 while( *line ==
' ' )
325 "Cannot call SCH_LEGACY_PLUGIN::LoadContent() without setting root sheet." );
331 char* line = aReader.
Line();
333 while( *line ==
' ' )
370 const char* line = aReader.
ReadLine();
372 if( !line || !
strCompare(
"Eeschema Schematic File Version", line, &line ) )
374 m_error.Printf(
_(
"'%s' does not appear to be an Eeschema file." ),
395 line = aReader.
Line();
397 while( *line ==
' ' )
410 wxASSERT( aScreen !=
nullptr );
413 const char* line = aReader.
Line();
418 wxCHECK_RET(
strCompare(
"$Descr", line, &line ),
"Invalid sheet description" );
425 int pagew =
parseInt( aReader, line, &line );
426 int pageh =
parseInt( aReader, line, &line );
435 wxString orientation;
441 if( orientation ==
"portrait" )
447 while( line !=
nullptr )
454 line = aReader.
Line();
481 else if(
strCompare(
"Comment1", line, &line ) )
486 else if(
strCompare(
"Comment2", line, &line ) )
491 else if(
strCompare(
"Comment3", line, &line ) )
496 else if(
strCompare(
"Comment4", line, &line ) )
501 else if(
strCompare(
"Comment5", line, &line ) )
506 else if(
strCompare(
"Comment6", line, &line ) )
511 else if(
strCompare(
"Comment7", line, &line ) )
516 else if(
strCompare(
"Comment8", line, &line ) )
521 else if(
strCompare(
"Comment9", line, &line ) )
539 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>();
541 const char* line = aReader.
ReadLine();
543 while( line !=
nullptr )
551 sheet->SetPosition( position );
557 sheet->SetSize( size );
564 if(
text !=
"00000000" )
567 else if( *line ==
'F' )
573 int fieldId =
parseInt( aReader, line, &line );
575 if( fieldId == 0 || fieldId == 1 )
580 SCH_FIELD& field = sheet->GetFields()[ fieldId ];
587 std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( sheet.get() );
589 sheetPin->SetNumber( fieldId );
596 if( line ==
nullptr )
599 switch(
parseChar( aReader, line, &line ) )
601 case 'I': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
break;
602 case 'O': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
break;
603 case 'B': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
break;
604 case 'T': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE );
break;
605 case 'U': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED );
break;
609 switch(
parseChar( aReader, line, &line ) )
611 case 'R': sheetPin->SetSide( SHEET_SIDE::RIGHT );
break;
612 case 'T': sheetPin->SetSide( SHEET_SIDE::TOP );
break;
613 case 'B': sheetPin->SetSide( SHEET_SIDE::BOTTOM );
break;
614 case 'L': sheetPin->SetSide( SHEET_SIDE::LEFT );
break;
623 sheetPin->SetPosition( position );
627 sheetPin->SetTextSize(
VECTOR2I( size, size ) );
629 sheet->AddPin( sheetPin.release() );
634 sheet->AutoplaceFields(
nullptr,
false );
635 return sheet.release();
649 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
651 const char* line = aReader.
Line();
653 wxCHECK(
strCompare(
"$Bitmap", line, &line ),
nullptr );
657 while( line !=
nullptr )
665 bitmap->SetPosition( position );
669 auto scalefactor =
parseDouble( aReader, line, &line );
675 if( !std::isnormal( scalefactor ) )
678 bitmap->GetImage()->SetScale( scalefactor );
682 wxMemoryBuffer buffer;
689 line = aReader.
Line();
694 bitmap->GetImage()->ReadImageFile( buffer );
710 int len = strlen( line );
712 for( ; len > 0 && !isspace( *line ) &&
'$' != *line; len -= 3, line += 3 )
716 if( sscanf( line,
"%X", &value ) == 1 )
717 buffer.AppendByte( (
char) value );
723 if( line ==
nullptr )
728 return bitmap.release();
740 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
742 const char* line = aReader.
Line();
744 wxCHECK(
strCompare(
"Connection", line, &line ),
nullptr );
754 junction->SetPosition( position );
756 return junction.release();
762 std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
764 const char* line = aReader.
Line();
766 wxCHECK(
strCompare(
"NoConn", line, &line ),
nullptr );
776 no_connect->SetPosition( position );
778 return no_connect.release();
784 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
786 const char* line = aReader.
Line();
788 wxCHECK(
strCompare(
"Wire", line, &line ),
nullptr );
816 wire->SetLineWidth( size );
822 if( buf == wxT(
"solid" ) )
823 wire->SetLineStyle( LINE_STYLE::SOLID );
824 else if( buf == wxT(
"dashed" ) )
825 wire->SetLineStyle( LINE_STYLE::DASH );
826 else if( buf == wxT(
"dash_dot" ) )
827 wire->SetLineStyle( LINE_STYLE::DASHDOT );
828 else if( buf == wxT(
"dotted" ) )
829 wire->SetLineStyle( LINE_STYLE::DOT );
837 wxString prm, keyword;
838 keyword = buf.BeforeLast(
'(', &prm );
842 long color[4] = { 0 };
848 prm.ToLong( &
color[ii] );
852 int prm_count = ( keyword ==
T_COLORA ) ? 4 : 3;
857 for(; ii < prm_count && !
is_eol( *line ); ii++ )
862 if( *line ==
',' || *line ==
' ')
881 wire->SetStartPoint( begin );
882 wire->SetEndPoint( end );
884 return wire.release();
890 const char* line = aReader.
Line();
892 wxCHECK(
strCompare(
"Entry", line, &line ),
nullptr );
894 std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
898 busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
901 SCH_PARSE_ERROR(
"invalid bus entry definition expected 'Line'", aReader, line );
905 busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
908 SCH_PARSE_ERROR(
"invalid bus entry definition expected 'Bus'", aReader, line );
928 busEntry->SetPosition( pos );
929 busEntry->SetSize( size );
931 return busEntry.release();
949 const char* line = aReader.
Line();
952 wxCHECK(
strCompare(
"Text", line, &line ),
nullptr );
962 else if(
strCompare(
"HLabel", line, &line ) )
966 else if(
strCompare(
"GLabel", line, &line ) )
984 std::unique_ptr<SCH_TEXT>
text;
995 int spinStyle =
parseInt( aReader, line, &line );
1014 if( spinStyle == 0 )
1016 else if( spinStyle == 2 )
1026 [ &line ](
const auto& it )
1028 return strCompare( it.second, line, &line );
1032 label->
SetShape( resultIt->first );
1047 text->SetItalic(
true );
1055 penWidth =
parseInt( aReader, line, &line );
1058 text->SetBold( penWidth != 0 );
1064 tmp = strtok( tmp,
"\r\n" );
1069 int i = val.find( wxT(
"\\n" ) );
1071 if( i == wxNOT_FOUND )
1075 val.insert( i, wxT(
"\n" ) );
1080 return text.release();
1086 const char* line = aReader.
Line();
1088 wxCHECK(
strCompare(
"$Comp", line, &line ),
nullptr );
1090 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1094 while( line !=
nullptr )
1100 wxString utf8Line = wxString::FromUTF8( line );
1101 wxStringTokenizer tokens( utf8Line,
" \r\n\t" );
1103 if( tokens.CountTokens() < 2 )
1107 libName = tokens.GetNextToken();
1108 libName.Replace(
"~",
" " );
1116 libId.
Parse( libName,
true );
1120 symbol->SetLibId( libId );
1122 wxString refDesignator = tokens.GetNextToken();
1124 refDesignator.Replace(
"~",
" " );
1126 wxString prefix = refDesignator;
1128 while( prefix.Length() )
1130 if( ( prefix.Last() <
'0' || prefix.Last() >
'9') && prefix.Last() !=
'?' )
1133 prefix.RemoveLast();
1137 prefix.Trim(
true );
1138 prefix.Trim(
false );
1140 if( prefix.IsEmpty() )
1141 symbol->SetPrefix( wxString(
"U" ) );
1143 symbol->SetPrefix( prefix );
1149 int unit =
parseInt( aReader, line, &line );
1160 symbol->SetUnit( unit );
1174 symbol->SetConvert(
convert );
1179 if(
text !=
"00000000" )
1188 symbol->SetPosition( pos );
1195 if( strncasecmp(
strCompare, line, len ) != 0 )
1199 wxString pathStr, reference, unit;
1207 if(
path.size() > 0 )
1219 if( strncasecmp(
strCompare, line, len ) != 0 )
1228 if( strncasecmp(
strCompare, line, len ) != 0 )
1236 if( !unit.ToLong( &tmp, 10 ) )
1242 symbol->AddHierarchicalReference(
path, reference, (
int)tmp );
1247 int index =
parseInt( aReader, line, &line );
1253 char orientation =
parseChar( aReader, line, &line );
1258 int attributes =
parseHex( aReader, line, &line );
1260 if( index >= symbol->GetFieldCount() )
1270 index = symbol->GetFieldCount();
1273 symbol->AddField( field );
1276 SCH_FIELD& field = symbol->GetFields()[index];
1282 char hjustify =
parseChar( aReader, line, &line );
1289 if( hjustify ==
'L' )
1291 else if( hjustify ==
'R' )
1293 else if( hjustify !=
'C' )
1294 SCH_PARSE_ERROR(
"symbol field text horizontal justification must be "
1295 "L, R, or C", aReader, line );
1299 if( textAttrs[0] ==
'T' )
1301 else if( textAttrs[0] ==
'B' )
1303 else if( textAttrs[0] !=
'C' )
1305 "B, T, or C", aReader, line );
1308 if( textAttrs.Length() > 1 )
1310 if( textAttrs.Length() != 3 )
1312 SCH_PARSE_ERROR(
_(
"symbol field text attributes must be 3 characters wide" ),
1316 if( textAttrs[1] ==
'I' )
1320 else if( textAttrs[1] !=
'N' )
1322 SCH_PARSE_ERROR(
"symbol field text italics indicator must be I or N",
1326 if( textAttrs[2] ==
'B' )
1330 else if( textAttrs[2] !=
'N' )
1343 if( orientation ==
'H' )
1345 else if( orientation ==
'V' )
1348 SCH_PARSE_ERROR(
"symbol field orientation must be H or V", aReader, line );
1350 if(
name.IsEmpty() )
1367 instance.
m_Unit = symbol->GetUnit();
1368 symbol->AddHierarchicalReference( instance );
1375 symbol->AddHierarchicalReference( tmpInstance );
1381 symbol->ClearFlags();
1382 return symbol.release();
1399 transform.
x1 =
parseInt( aReader, line, &line );
1401 if( transform.
x1 < -1 || transform.
x1 > 1 )
1402 SCH_PARSE_ERROR(
"invalid symbol X1 transform value", aReader, line );
1404 transform.
y1 =
parseInt( aReader, line, &line );
1406 if( transform.
y1 < -1 || transform.
y1 > 1 )
1407 SCH_PARSE_ERROR(
"invalid symbol Y1 transform value", aReader, line );
1409 transform.
x2 =
parseInt( aReader, line, &line );
1411 if( transform.
x2 < -1 || transform.
x2 > 1 )
1412 SCH_PARSE_ERROR(
"invalid symbol X2 transform value", aReader, line );
1414 transform.
y2 =
parseInt( aReader, line, &line );
1416 if( transform.
y2 < -1 || transform.
y2 > 1 )
1417 SCH_PARSE_ERROR(
"invalid symbol Y2 transform value", aReader, line );
1419 symbol->SetTransform( transform );
1434 auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
1435 const char* line = aReader.
Line();
1437 wxCHECK(
strCompare(
"BusAlias", line, &line ),
nullptr );
1441 busAlias->SetName( buf );
1443 while( *line !=
'\0' )
1448 if( !buf.IsEmpty() )
1449 busAlias->Members().emplace_back( buf );
1460 wxCHECK_RET( aSheet !=
nullptr,
"NULL SCH_SHEET object." );
1461 wxCHECK_RET( !aFileName.IsEmpty(),
"No schematic file name defined." );
1465 init( aSchematic, aProperties );
1467 wxFileName fn = aFileName;
1471 wxASSERT( fn.IsAbsolute() );
1485 wxCHECK_RET( aSheet !=
nullptr,
"NULL SCH_SHEET* object." );
1486 wxCHECK_RET(
m_schematic !=
nullptr,
"NULL SCHEMATIC* object." );
1528 for(
const std::shared_ptr<BUS_ALIAS>& alias : screen->
GetBusAliases() )
1533 std::multiset<
SCH_ITEM*,
decltype( cmp )> save_map( cmp );
1536 save_map.insert( item );
1539 for(
auto& item : save_map )
1541 switch( item->Type() )
1572 wxASSERT(
"Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1584 for(
unsigned i = 0; i < aSelection->
GetSize(); ++i )
1588 switch( item->
Type() )
1619 wxASSERT(
"Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1630 static wxString delimiters( wxT(
" " ) );
1648 if( symbol_name.size() )
1658 m_out->
Print( 0,
"L %s %s\n", name2.c_str(), name1.c_str() );
1687 wxString
path =
"/";
1690 for(
int i = 1; i < (int) instance.m_Path.size(); ++i )
1691 path += instance.m_Path[i].AsLegacyTimestampString() +
"/";
1693 m_out->
Print( 0,
"AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
1695 TO_UTF8( instance.m_Reference ),
1726 transform.
x1, transform.
y1, transform.
x2, transform.
y2 );
1733 char hjustify =
'C';
1740 char vjustify =
'C';
1747 m_out->
Print( 0,
"F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1757 aField->
IsBold() ?
'B' :
'N' );
1769 wxCHECK_RET( aBitmap !=
nullptr,
"SCH_BITMAP* is NULL" );
1773 wxCHECK_RET(
image !=
nullptr,
"wxImage* is NULL" );
1782 wxMemoryOutputStream stream;
1784 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1787 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1788 char* begin = (
char*) buffer->GetBufferStart();
1790 for(
int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1809 wxCHECK_RET( aSheet !=
nullptr,
"SCH_SHEET* is NULL" );
1823 if( !sheetName.
GetText().IsEmpty() )
1830 if( !fileName.
GetText().IsEmpty() )
1841 if(
pin->GetText().IsEmpty() )
1844 switch(
pin->GetSide() )
1847 case SHEET_SIDE::LEFT: side =
'L';
break;
1848 case SHEET_SIDE::RIGHT: side =
'R';
break;
1849 case SHEET_SIDE::TOP: side =
'T';
break;
1850 case SHEET_SIDE::BOTTOM: side =
'B';
break;
1853 switch(
pin->GetShape() )
1856 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: type =
'U';
break;
1857 case LABEL_FLAG_SHAPE::L_INPUT: type =
'I';
break;
1858 case LABEL_FLAG_SHAPE::L_OUTPUT: type =
'O';
break;
1859 case LABEL_FLAG_SHAPE::L_BIDI: type =
'B';
break;
1860 case LABEL_FLAG_SHAPE::L_TRISTATE: type =
'T';
break;
1863 m_out->
Print( 0,
"F%d %s %c %c %-3d %-3d %-3d\n",
1877 wxCHECK_RET( aJunction !=
nullptr,
"SCH_JUNCTION* is NULL" );
1887 wxCHECK_RET( aNoConnect !=
nullptr,
"SCH_NOCONNECT* is NULL" );
1897 wxCHECK_RET( aBusEntry !=
nullptr,
"SCH_BUS_ENTRY_BASE* is NULL" );
1901 m_out->
Print( 0,
"Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
1909 m_out->
Print( 0,
"Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
1920 wxCHECK_RET( aLine !=
nullptr,
"SCH_LINE* is NULL" );
1922 const char* layer =
"Notes";
1923 const char* width =
"Line";
1930 m_out->
Print( 0,
"Wire %s %s", layer, width );
1962 wxCHECK_RET( aText !=
nullptr,
"SCH_TEXT* is NULL" );
1964 const char* italics =
"~";
1965 const char* textType =
"Notes";
1980 text.Replace( wxT(
"\n" ), wxT(
"\\n" ) );
1988 for(
unsigned ii = 0; ii <
text.Len(); )
1990 if(
text[ii] == 0x0A ||
text[ii] == 0x0D )
1991 text.erase( ii, 1 );
2006 spinStyle =
static_cast<int>( label->GetSpinStyle() );
2008 if( spinStyle == 0 )
2010 else if( spinStyle == 2 )
2014 m_out->
Print( 0,
"Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2027 wxCHECK_RET( shapeLabelIt !=
sheetLabelNames.end(),
"Shape not found in names list" );
2029 m_out->
Print( 0,
"Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2034 shapeLabelIt->second,
2043 wxCHECK_RET( aAlias !=
nullptr,
"BUS_ALIAS* is NULL" );
2045 wxString members = boost::algorithm::join( aAlias->Members(),
" " );
2070 if( aProperties && aProperties->find( propName ) != aProperties->end() )
2094 const wxString& aLibraryPath,
2099 bool powerSymbolsOnly = ( aProperties &&
2102 cacheLib( aLibraryPath, aProperties );
2106 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2108 if( !powerSymbolsOnly || it->second->IsPower() )
2109 aSymbolNameList.Add( it->first );
2115 const wxString& aLibraryPath,
2120 bool powerSymbolsOnly = ( aProperties &&
2123 cacheLib( aLibraryPath, aProperties );
2127 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2129 if( !powerSymbolsOnly || it->second->IsPower() )
2130 aSymbolList.push_back( it->second );
2136 const wxString& aSymbolName,
2141 cacheLib( aLibraryPath, aProperties );
2143 LIB_SYMBOL_MAP::const_iterator it =
m_cache->
m_symbols.find( aSymbolName );
2157 cacheLib( aLibraryPath, aProperties );
2171 cacheLib( aLibraryPath, aProperties );
2183 if( wxFileExists( aLibraryPath ) )
2185 THROW_IO_ERROR( wxString::Format(
_(
"Symbol library '%s' already exists." ),
2186 aLibraryPath.GetData() ) );
2202 wxFileName fn = aLibraryPath;
2204 if( !fn.FileExists() )
2209 if( wxRemove( aLibraryPath ) )
2211 THROW_IO_ERROR( wxString::Format(
_(
"Symbol library '%s' cannot be deleted." ),
2212 aLibraryPath.GetData() ) );
constexpr EDA_IU_SCALE schIUScale
void SetPageCount(int aPageCount)
int GetVirtualPageNumber() const
void SetVirtualPageNumber(int aPageNumber)
void SetContentModified(bool aModified=true)
This class handle bitmap images in KiCad.
void SetScale(double aScale)
bool IsHorizontal() const
KICAD_T Type() const
Returns the type of object.
virtual void SetParent(EDA_ITEM *aParent)
void SetTextSize(VECTOR2I aNewSize)
const EDA_ANGLE & GetTextAngle() const
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
virtual void SetVisible(bool aVisible)
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
int GetTextThickness() const
void SetItalic(bool aItalic)
VECTOR2I GetTextSize() const
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
EE_TYPE OfType(KICAD_T aType) const
A LINE_READER that reads from an open file.
void Rewind()
Rewind the file and resets the line number back to zero.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
wxString ToCSSString() const
wxString AsLegacyTimestampString() const
timestamp_t AsLegacyTimestamp() const
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Define a library symbol object.
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.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
static const wxChar Custom[]
"User" defined page type
void SetHeightMils(double aHeightInMils)
double GetHeightMils() const
const wxString & GetType() const
double GetWidthMils() const
void SetWidthMils(double aWidthInMils)
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
virtual const wxString GetProjectPath() const
Return the full path of the project.
Holds all the data relating to one schematic.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Object to handle a bitmap image that can be inserted in a schematic.
VECTOR2I GetPosition() const override
BITMAP_BASE * GetImage() const
Base class for a bus or wire entry.
VECTOR2I GetPosition() const override
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
VECTOR2I GetLibPosition() const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
VECTOR2I GetPosition() const override
SPIN_STYLE GetSpinStyle() const
void SetShape(LABEL_FLAG_SHAPE aShape)
LABEL_FLAG_SHAPE GetShape() const
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
A cache assistant for KiCad legacy symbol libraries.
void Save(const std::optional< bool > &aOpt) override
Save the entire library to file m_libFileName;.
void DeleteSymbol(const wxString &aName) override
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)
static LIB_SYMBOL * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_SYMBOL_MAP *aMap=nullptr)
int m_version
Version of file being loaded.
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
unsigned m_lastProgressLine
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified symbol library file.
SCH_LINE * loadWire(LINE_READER &aReader)
void saveSymbol(SCH_SYMBOL *aSymbol)
int GetModifyHash() const override
Return the modification hash from the library cache.
wxString m_error
For throwing exceptions or errors on partial schematic loads.
void SaveLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
void saveSheet(SCH_SHEET *aSheet)
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
wxString m_path
Root project path for loading child sheets.
void saveText(SCH_TEXT *aText)
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
bool writeDocFile(const STRING_UTF8_MAP *aProperties)
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified schematic file.
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
void Format(SCH_SHEET *aSheet)
void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Create a new empty symbol library at aLibraryPath.
void saveField(SCH_FIELD *aField)
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.
void saveJunction(SCH_JUNCTION *aJunction)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
void saveLine(SCH_LINE *aLine)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
bool DeleteSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing symbol library and returns true if successful, or if library does not exist return...
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
static LIB_SYMBOL * ParsePart(LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
unsigned m_lineCount
for progress reporting
SCH_SHEET * loadSheet(LINE_READER &aReader)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
static void FormatPart(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aScreen, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr) override
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_TEXT * loadText(LINE_READER &aReader)
void saveBitmap(SCH_BITMAP *aBitmap)
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
virtual ~SCH_LEGACY_PLUGIN()
bool isBuffering(const STRING_UTF8_MAP *aProperties)
LINE_READER * m_lineReader
for progress reporting
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
void loadHierarchy(SCH_SHEET *aSheet)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
SCH_LEGACY_PLUGIN_CACHE * m_cache
SCH_SHEET * m_currentSheet
The sheet currently being loaded.
bool IsFile(const wxString &aFullPathAndFileName) const
wxString GetFileName() const
bool IsFileChanged() const
void SetFileName(const wxString &aFileName)
virtual void AddSymbol(const LIB_SYMBOL *aSymbol)
void SetModified(bool aModified=true)
Segment description base class to describe items which have 2 end points (track, wire,...
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
LINE_STYLE GetLineStyle() const
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
VECTOR2I GetPosition() const override
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified schematic file.
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified symbol library file.
const PAGE_INFO & GetPageSettings() const
auto & GetBusAliases() const
Return a set of bus aliases defined in this screen.
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Add a bus alias definition (and transfers ownership of the pointer).
void SetPageSettings(const PAGE_INFO &aPageSettings)
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
const wxString & GetFileName() const
const KIID & GetUuid() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
const TITLE_BLOCK & GetTitleBlock() const
void SetFileReadOnly(bool aIsReadOnly)
void SetFileExists(bool aFileExists)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
wxString GetFileName() const
Return the filename corresponding to this sheet.
std::vector< SCH_FIELD > & GetFields()
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
SCH_SCREEN * GetScreen() const
VECTOR2I GetPosition() const override
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
std::vector< SCH_SHEET_PIN * > & GetPins()
int GetFieldCount() const
Return the number of fields in this symbol.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstanceReferences() const
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
VECTOR2I GetPosition() const override
TRANSFORM & GetTransform()
const LIB_ID & GetLibId() const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
wxString GetPrefix() const
VECTOR2I GetPosition() const override
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
virtual unsigned int GetSize() const override
Return the number of stored items.
A name/value tuple with unique names and optional values.
bool Exists(const std::string &aProperty) const
static wxString GetLineStyleToken(LINE_STYLE aStyle)
static const char * PropPowerSymsOnly
Hold the information shown in the lower right corner of a plot, printout, or editing view.
const wxString & GetCompany() const
void SetRevision(const wxString &aRevision)
void SetComment(int aIdx, const wxString &aComment)
const wxString & GetRevision() const
void SetTitle(const wxString &aTitle)
const wxString & GetDate() const
const wxString & GetComment(int aIdx) const
void SetCompany(const wxString &aCompany)
const wxString & GetTitle() const
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
static constexpr EDA_ANGLE & ANGLE_VERTICAL
#define MAX_UNIT_COUNT_PER_PACKAGE
The maximum number of units per package.
#define SCHEMATIC_HEAD_STRING
int GetPenSizeForBold(int aTextSize)
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
#define SCH_LAYER_ID_COUNT
SCH_LAYER_ID
Eeschema drawing layers.
bool fileStartsWithPrefix(const wxString &aFilePath, const wxString &aPrefix, bool aIgnoreWhitespace)
Check if a file starts with a defined string.
const std::map< LABEL_FLAG_SHAPE, const char * > sheetLabelNames
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.
uint32_t parseHex(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
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.
double parseDouble(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parses an ASCII point string with possible leading whitespace into a double precision floating point ...
#define SCH_PARSE_ERROR(text, reader, pos)
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
wxString From_UTF8(const char *cstring)
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
constexpr int IUToMils(int iu) const
constexpr int MilsToIU(int mils) const
A simple container for schematic symbol instance information.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
Definition for symbol library class.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition of file extensions used in Kicad.