KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN_CACHE Class Reference

A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLUGIN, so therefore is private to this implementation file, i.e. More...

Public Member Functions

 SCH_LEGACY_PLUGIN_CACHE (const wxString &aLibraryPath)
 
 ~SCH_LEGACY_PLUGIN_CACHE ()
 
int GetModifyHash () const
 
void Save (bool aSaveDocFile=true)
 Save the entire library to file m_libFileName;. More...
 
void Load ()
 
void AddSymbol (const LIB_PART *aPart)
 
void DeleteSymbol (const wxString &aName)
 
wxFileName GetRealFile () const
 
wxDateTime GetLibModificationTime ()
 
bool IsFile (const wxString &aFullPathAndFileName) const
 
bool IsFileChanged () const
 
void SetModified (bool aModified=true)
 
wxString GetLogicalName () const
 
void SetFileName (const wxString &aFileName)
 
wxString GetFileName () const
 

Static Public Member Functions

static LIB_PARTLoadPart (LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_PART_MAP *aMap=nullptr)
 
static void SaveSymbol (LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_PART_MAP *aMap=nullptr)
 

Private Member Functions

void loadHeader (FILE_LINE_READER &aReader)
 
void loadDocs ()
 
LIB_PARTremoveSymbol (LIB_PART *aAlias)
 
void saveDocFile ()
 

Static Private Member Functions

static void loadAliases (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, LIB_PART_MAP *aMap=nullptr)
 
static void loadField (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static void loadDrawEntries (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static void loadFootprintFilters (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_ARCloadArc (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_CIRCLEloadCircle (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_TEXTloadText (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static LIB_RECTANGLEloadRectangle (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_PINloadPin (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_POLYLINEloadPolyLine (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_BEZIERloadBezier (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static FILL_T parseFillMode (LINE_READER &aReader, const char *aLine, const char **aOutput)
 
static void saveArc (LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter)
 
static void saveBezier (LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter)
 
static void saveCircle (LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter)
 
static void saveField (LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
 
static void savePin (LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
 
static void savePolyLine (LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
 
static void saveRectangle (LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
 
static void saveText (LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
 

Private Attributes

wxString m_fileName
 
wxFileName m_libFileName
 
wxDateTime m_fileModTime
 
LIB_PART_MAP m_symbols
 
bool m_isWritable
 
bool m_isModified
 
int m_versionMajor
 
int m_versionMinor
 
int m_libType
 
friend SCH_LEGACY_PLUGIN
 

Static Private Attributes

static int m_modHash = 1
 

Detailed Description

A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLUGIN, so therefore is private to this implementation file, i.e.

not placed into a header.

Definition at line 473 of file sch_legacy_plugin.cpp.

Constructor & Destructor Documentation

◆ SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE ( const wxString &  aLibraryPath)

Definition at line 2394 of file sch_legacy_plugin.cpp.

2394  :
2395  m_fileName( aFullPathAndFileName ),
2396  m_libFileName( aFullPathAndFileName ),
2397  m_isWritable( true ),
2398  m_isModified( false )
2399 {
2400  m_versionMajor = -1;
2401  m_versionMinor = -1;
2403 }

References LIBRARY_TYPE_EESCHEMA, m_libType, m_versionMajor, and m_versionMinor.

◆ ~SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE ( )

Definition at line 2406 of file sch_legacy_plugin.cpp.

2407 {
2408  std::vector< LIB_PART* > rootParts;
2409 
2410  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2411  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
2412  delete it->second;
2413 
2414  m_symbols.clear();
2415 }

References m_symbols.

Member Function Documentation

◆ AddSymbol()

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 2536 of file sch_legacy_plugin.cpp.

2537 {
2538  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2539  wxString name = aPart->GetName();
2540  LIB_PART_MAP::iterator it = m_symbols.find( name );
2541 
2542  if( it != m_symbols.end() )
2543  {
2544  removeSymbol( it->second );
2545  }
2546 
2547  m_symbols[ name ] = const_cast< LIB_PART* >( aPart );
2548  m_isModified = true;
2549  ++m_modHash;
2550 }
wxString GetName() const override
const char * name
Definition: DXF_plotter.cpp:60
LIB_PART * removeSymbol(LIB_PART *aAlias)

References LIB_PART::GetName(), m_isModified, m_modHash, m_symbols, name, and removeSymbol().

Referenced by SCH_LEGACY_PLUGIN::SaveSymbol().

◆ DeleteSymbol()

void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aName)

Definition at line 4267 of file sch_legacy_plugin.cpp.

4268 {
4269  LIB_PART_MAP::iterator it = m_symbols.find( aSymbolName );
4270 
4271  if( it == m_symbols.end() )
4272  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
4273  m_libFileName.GetFullName(), aSymbolName ) );
4274 
4275  LIB_PART* part = it->second;
4276 
4277  if( part->IsRoot() )
4278  {
4279  LIB_PART* rootPart = part;
4280 
4281  // Remove the root symbol and all it's children.
4282  m_symbols.erase( it );
4283 
4284  LIB_PART_MAP::iterator it1 = m_symbols.begin();
4285 
4286  while( it1 != m_symbols.end() )
4287  {
4288  if( it1->second->IsAlias() && it1->second->GetParent().lock() == rootPart->SharedPtr() )
4289  {
4290  delete it1->second;
4291  it1 = m_symbols.erase( it1 );
4292  }
4293  else
4294  {
4295  it1++;
4296  }
4297  }
4298 
4299  delete rootPart;
4300  }
4301  else
4302  {
4303  // Just remove the alias.
4304  m_symbols.erase( it );
4305  delete part;
4306  }
4307 
4308  ++m_modHash;
4309  m_isModified = true;
4310 }
PART_SPTR SharedPtr()
Define a library symbol object.
#define THROW_IO_ERROR(msg)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.

References _, Format(), LIB_PART::IsRoot(), m_isModified, m_libFileName, m_modHash, m_symbols, LIB_PART::SharedPtr(), and THROW_IO_ERROR.

Referenced by SCH_LEGACY_PLUGIN::DeleteSymbol().

◆ GetFileName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 556 of file sch_legacy_plugin.cpp.

556 { return m_libFileName.GetFullPath(); }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ GetLibModificationTime()

wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2442 of file sch_legacy_plugin.cpp.

2443 {
2444  wxFileName fn = GetRealFile();
2445 
2446  // update the writable flag while we have a wxFileName, in a network this
2447  // is possibly quite dynamic anyway.
2448  m_isWritable = fn.IsFileWritable();
2449 
2450  return fn.GetModificationTime();
2451 }
wxFileName GetRealFile() const

References GetRealFile(), and m_isWritable.

Referenced by Load().

◆ GetLogicalName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 552 of file sch_legacy_plugin.cpp.

552 { return m_libFileName.GetName(); }

References m_libFileName.

◆ GetModifyHash()

int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline

Definition at line 526 of file sch_legacy_plugin.cpp.

526 { return m_modHash; }

References m_modHash.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

◆ GetRealFile()

wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile ( ) const

Definition at line 2419 of file sch_legacy_plugin.cpp.

2420 {
2421  wxFileName fn( m_libFileName );
2422 
2423 #ifndef __WINDOWS__
2424  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2425  {
2426  char buffer[ PATH_MAX + 1 ];
2427  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2428 
2429  if( pathLen > 0 )
2430  {
2431  buffer[ pathLen ] = '\0';
2432  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2433  fn.Normalize();
2434  }
2435  }
2436 #endif
2437 
2438  return fn;
2439 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48

References m_libFileName, and TO_UTF8.

Referenced by GetLibModificationTime(), IsFileChanged(), and Save().

◆ IsFile()

bool SCH_LEGACY_PLUGIN_CACHE::IsFile ( const wxString &  aFullPathAndFileName) const

Definition at line 2454 of file sch_legacy_plugin.cpp.

2455 {
2456  return m_fileName == aFullPathAndFileName;
2457 }

References m_fileName.

Referenced by SCH_LEGACY_PLUGIN::cacheLib(), SCH_LEGACY_PLUGIN::DeleteSymbolLib(), and SCH_LEGACY_PLUGIN::SaveLibrary().

◆ IsFileChanged()

bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2460 of file sch_legacy_plugin.cpp.

2461 {
2462  wxFileName fn = GetRealFile();
2463 
2464  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2465  return fn.GetModificationTime() != m_fileModTime;
2466 
2467  return false;
2468 }
wxFileName GetRealFile() const

References GetRealFile(), and m_fileModTime.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

◆ Load()

void SCH_LEGACY_PLUGIN_CACHE::Load ( )
Todo:
Probably should check for a valid date and time stamp even though it's not used.

Definition at line 2553 of file sch_legacy_plugin.cpp.

2554 {
2555  if( !m_libFileName.FileExists() )
2556  {
2557  THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ),
2558  m_libFileName.GetFullPath() ) );
2559  }
2560 
2561  wxCHECK_RET( m_libFileName.IsAbsolute(),
2562  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2563  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2564 
2565  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2566  m_libFileName.GetFullPath() );
2567 
2568  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2569 
2570  if( !reader.ReadLine() )
2571  THROW_IO_ERROR( _( "unexpected end of file" ) );
2572 
2573  const char* line = reader.Line();
2574 
2575  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2576  {
2577  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2578  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2579  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2580  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2581  }
2582 
2583  m_versionMajor = parseInt( reader, line, &line );
2584 
2585  if( *line != '.' )
2586  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2587 
2588  line++;
2589 
2590  m_versionMinor = parseInt( reader, line, &line );
2591 
2592  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2593  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2594 
2595  // Check if this is a symbol library which is the same as a component library but without
2596  // any alias, documentation, footprint filters, etc.
2597  if( strCompare( "SYMBOL", line, &line ) )
2598  {
2599  // Symbol files add date and time stamp info to the header.
2601 
2603  }
2604  else
2605  {
2607  }
2608 
2609  while( reader.ReadLine() )
2610  {
2611  line = reader.Line();
2612 
2613  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2614  continue;
2615 
2616  // Headers where only supported in older library file formats.
2617  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2618  loadHeader( reader );
2619 
2620  if( strCompare( "DEF", line ) )
2621  {
2622  // Read one DEF/ENDDEF part entry from library:
2624 
2625  m_symbols[ part->GetName() ] = part;
2626  }
2627  }
2628 
2629  ++m_modHash;
2630 
2631  // Remember the file modification time of library file when the
2632  // cache snapshot was made, so that in a networked environment we will
2633  // reload the cache as needed.
2635 
2637  loadDocs();
2638 }
wxString GetName() const override
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
void loadHeader(FILE_LINE_READER &aReader)
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
Define a library symbol object.
#define THROW_IO_ERROR(msg)
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
Definition: class_library.h:74
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static LIB_PART * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_PART_MAP *aMap=nullptr)
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References _, Format(), GetLibModificationTime(), LIB_PART::GetName(), LIBRARY_TYPE_EESCHEMA, LIBRARY_TYPE_SYMBOL, loadDocs(), loadHeader(), LoadPart(), m_fileModTime, m_libFileName, m_libType, m_modHash, m_symbols, m_versionMajor, m_versionMinor, parseInt(), SCH_PARSE_ERROR, strCompare(), THROW_IO_ERROR, traceSchLegacyPlugin, and USE_OLD_DOC_FILE_FORMAT.

Referenced by SCH_LEGACY_PLUGIN::cacheLib(), and SCH_LEGACY_PLUGIN::CreateSymbolLib().

◆ loadAliases()

void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader,
LIB_PART_MAP aMap = nullptr 
)
staticprivate

Definition at line 2940 of file sch_legacy_plugin.cpp.

2943 {
2944  wxString newAliasName;
2945  const char* line = aReader.Line();
2946 
2947  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2948 
2949  wxString utf8Line = wxString::FromUTF8( line );
2950  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2951 
2952  // Parse the ALIAS list.
2953  while( tokens.HasMoreTokens() )
2954  {
2955  newAliasName = tokens.GetNextToken();
2956 
2957  if( aMap )
2958  {
2959  LIB_PART* newPart = new LIB_PART( newAliasName );
2960 
2961  newPart->SetParent( aPart.get() );
2962 
2963  // This will prevent duplicate aliases.
2964  (*aMap)[ newPart->GetName() ] = newPart;
2965  }
2966  }
2967 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
wxString GetName() const override
void SetParent(LIB_PART *aParent=nullptr)
Define a library symbol object.
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LIB_PART::GetName(), LINE_READER::Line(), LIB_PART::SetParent(), and strCompare().

Referenced by LoadPart().

◆ loadArc()

LIB_ARC * SCH_LEGACY_PLUGIN_CACHE::loadArc ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3201 of file sch_legacy_plugin.cpp.

3203 {
3204  const char* line = aReader.Line();
3205 
3206  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
3207 
3208  LIB_ARC* arc = new LIB_ARC( aPart.get() );
3209 
3210  wxPoint center;
3211 
3212  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3213  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3214 
3215  arc->SetPosition( center );
3216  arc->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
3217 
3218  int angle1 = parseInt( aReader, line, &line );
3219  int angle2 = parseInt( aReader, line, &line );
3220 
3221  NORMALIZE_ANGLE_POS( angle1 );
3222  NORMALIZE_ANGLE_POS( angle2 );
3223  arc->SetFirstRadiusAngle( angle1 );
3224  arc->SetSecondRadiusAngle( angle2 );
3225 
3226  arc->SetUnit( parseInt( aReader, line, &line ) );
3227  arc->SetConvert( parseInt( aReader, line, &line ) );
3228  arc->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3229 
3230  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3231  // when fill mode is no fill (default mode).
3232  if( *line != 0 )
3233  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3234 
3235  // Actual Coordinates of arc ends are read from file
3236  if( *line != 0 )
3237  {
3238  wxPoint arcStart, arcEnd;
3239 
3240  arcStart.x = Mils2Iu( parseInt( aReader, line, &line ) );
3241  arcStart.y = Mils2Iu( parseInt( aReader, line, &line ) );
3242  arcEnd.x = Mils2Iu( parseInt( aReader, line, &line ) );
3243  arcEnd.y = Mils2Iu( parseInt( aReader, line, &line ) );
3244 
3245  arc->SetStart( arcStart );
3246  arc->SetEnd( arcEnd );
3247  }
3248  else
3249  {
3250  // Actual Coordinates of arc ends are not read from file
3251  // (old library), calculate them
3252  wxPoint arcStart( arc->GetRadius(), 0 );
3253  wxPoint arcEnd( arc->GetRadius(), 0 );
3254 
3255  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3256  arcStart += arc->GetPosition();
3257  arc->SetStart( arcStart );
3258  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3259  arcEnd += arc->GetPosition();
3260  arc->SetEnd( arcEnd );
3261  }
3262 
3263  return arc;
3264 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:260
void SetFirstRadiusAngle(int aAngle)
Definition: lib_arc.h:107
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:257
#define Mils2Iu(x)
void SetWidth(int aWidth) override
Definition: lib_arc.h:102
void SetEnd(const wxPoint &aPoint)
Definition: lib_arc.h:117
#define NULL
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:314
void SetSecondRadiusAngle(int aAngle)
Definition: lib_arc.h:110
int GetRadius() const
Definition: lib_arc.h:105
void SetConvert(int aConvert)
Definition: lib_item.h:311
void SetUnit(int aUnit)
Definition: lib_item.h:308
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetRadius(int aRadius)
Definition: lib_arc.h:104
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetStart(const wxPoint &aPoint)
Definition: lib_arc.h:114
wxPoint GetPosition() const override
Definition: lib_arc.h:92

References LIB_ARC::GetPosition(), LIB_ARC::GetRadius(), LINE_READER::Line(), Mils2Iu, NORMALIZE_ANGLE_POS(), NULL, parseFillMode(), parseInt(), RotatePoint(), LIB_ITEM::SetConvert(), LIB_ARC::SetEnd(), LIB_ITEM::SetFillMode(), LIB_ARC::SetFirstRadiusAngle(), LIB_ITEM::SetPosition(), LIB_ARC::SetRadius(), LIB_ARC::SetSecondRadiusAngle(), LIB_ARC::SetStart(), LIB_ITEM::SetUnit(), LIB_ARC::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadBezier()

LIB_BEZIER * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3674 of file sch_legacy_plugin.cpp.

3676 {
3677  const char* line = aReader.Line();
3678 
3679  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3680 
3681  LIB_BEZIER* bezier = new LIB_BEZIER( aPart.get() );
3682 
3683  int points = parseInt( aReader, line, &line );
3684  bezier->SetUnit( parseInt( aReader, line, &line ) );
3685  bezier->SetConvert( parseInt( aReader, line, &line ) );
3686  bezier->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3687 
3688  wxPoint pt;
3689  bezier->Reserve( points );
3690 
3691  for( int i = 0; i < points; i++ )
3692  {
3693  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3694  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3695  bezier->AddPoint( pt );
3696  }
3697 
3698  if( *line != 0 )
3699  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3700 
3701  return bezier;
3702 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define Mils2Iu(x)
void Reserve(size_t aCount)
Definition: lib_bezier.h:60
#define NULL
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:314
void SetConvert(int aConvert)
Definition: lib_item.h:311
void SetUnit(int aUnit)
Definition: lib_item.h:308
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetWidth(int aWidth) override
Definition: lib_bezier.h:92
void AddPoint(const wxPoint &aPoint)
Definition: lib_bezier.h:61
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34

References LIB_BEZIER::AddPoint(), LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_BEZIER::Reserve(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetUnit(), LIB_BEZIER::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadCircle()

LIB_CIRCLE * SCH_LEGACY_PLUGIN_CACHE::loadCircle ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3267 of file sch_legacy_plugin.cpp.

3269 {
3270  const char* line = aReader.Line();
3271 
3272  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3273 
3274  LIB_CIRCLE* circle = new LIB_CIRCLE( aPart.get() );
3275 
3276  wxPoint center;
3277 
3278  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3279  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3280 
3281  circle->SetPosition( center );
3282  circle->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
3283  circle->SetUnit( parseInt( aReader, line, &line ) );
3284  circle->SetConvert( parseInt( aReader, line, &line ) );
3285  circle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3286 
3287  if( *line != 0 )
3288  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3289 
3290  return circle;
3291 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:260
#define Mils2Iu(x)
#define NULL
void SetRadius(int aRadius)
Definition: lib_circle.h:91
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:314
void SetConvert(int aConvert)
Definition: lib_item.h:311
void SetUnit(int aUnit)
Definition: lib_item.h:308
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetWidth(int aWidth) override
Definition: lib_circle.h:89

References LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetPosition(), LIB_CIRCLE::SetRadius(), LIB_ITEM::SetUnit(), LIB_CIRCLE::SetWidth(), strCompare(), and wxPoint::x.

Referenced by loadDrawEntries().

◆ loadDocs()

void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2641 of file sch_legacy_plugin.cpp.

2642 {
2643  const char* line;
2644  wxString text;
2645  wxString aliasName;
2646  wxFileName fn = m_libFileName;
2647  LIB_PART* symbol = NULL;;
2648 
2649  fn.SetExt( DOC_EXT );
2650 
2651  // Not all libraries will have a document file.
2652  if( !fn.FileExists() )
2653  return;
2654 
2655  if( !fn.IsFileReadable() )
2656  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2657  "document file \"%s\"" ), fn.GetFullPath() ) );
2658 
2659  FILE_LINE_READER reader( fn.GetFullPath() );
2660 
2661  line = reader.ReadLine();
2662 
2663  if( !line )
2664  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2665 
2666  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2667  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2668  reader, line );
2669 
2670  while( reader.ReadLine() )
2671  {
2672  line = reader.Line();
2673 
2674  if( *line == '#' ) // Comment line.
2675  continue;
2676 
2677  if( !strCompare( "$CMP", line, &line ) != 0 )
2678  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2679 
2680  aliasName = wxString::FromUTF8( line );
2681  aliasName.Trim();
2682  aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH );
2683 
2684  LIB_PART_MAP::iterator it = m_symbols.find( aliasName );
2685 
2686  if( it == m_symbols.end() )
2687  wxLogWarning( "Symbol '%s' not found in library:\n\n"
2688  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2689  reader.LineNumber(), (int) (line - reader.Line() ) );
2690  else
2691  symbol = it->second;
2692 
2693  // Read the curent alias associated doc.
2694  // if the alias does not exist, just skip the description
2695  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2696  while( reader.ReadLine() )
2697  {
2698  line = reader.Line();
2699 
2700  if( !line )
2701  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2702 
2703  if( strCompare( "$ENDCMP", line, &line ) )
2704  break;
2705 
2706  text = FROM_UTF8( line + 2 );
2707  // Remove spaces at eol, and eol chars:
2708  text = text.Trim();
2709 
2710  switch( line[0] )
2711  {
2712  case 'D':
2713  if( symbol )
2714  symbol->SetDescription( text );
2715  break;
2716 
2717  case 'K':
2718  if( symbol )
2719  symbol->SetKeyWords( text );
2720  break;
2721 
2722  case 'F':
2723  if( symbol )
2724  {
2725  symbol->SetDocFileName( text );
2726  symbol->GetField( DATASHEET )->SetText( text );
2727  }
2728  break;
2729 
2730  case 0:
2731  case '\n':
2732  case '\r':
2733  case '#':
2734  // Empty line or commment
2735  break;
2736 
2737  default:
2738  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2739  }
2740  }
2741  }
2742 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
name of datasheet
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define DOCFILE_IDENT
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
#define NULL
void SetDescription(const wxString &aDescription)
void SetDocFileName(const wxString &aDocFileName)
Define a library symbol object.
#define DOC_EXT
Definition: class_library.h:49
#define THROW_IO_ERROR(msg)
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
void SetKeyWords(const wxString &aKeyWords)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:352
LIB_FIELD * GetField(int aId) const
Return pointer to the requested field.

References _, DATASHEET, DOC_EXT, DOCFILE_IDENT, LIB_ID::FixIllegalChars(), Format(), FROM_UTF8(), LIB_PART::GetField(), LIB_ID::ID_SCH, m_libFileName, m_symbols, NULL, FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_PART::SetDescription(), LIB_PART::SetDocFileName(), LIB_PART::SetKeyWords(), EDA_TEXT::SetText(), strCompare(), and THROW_IO_ERROR.

Referenced by Load().

◆ loadDrawEntries()

void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion 
)
staticprivate

Definition at line 3118 of file sch_legacy_plugin.cpp.

3122 {
3123  const char* line = aReader.Line();
3124 
3125  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
3126 
3127  line = aReader.ReadLine();
3128 
3129  while( line )
3130  {
3131  if( strCompare( "ENDDRAW", line, &line ) )
3132  return;
3133 
3134  switch( line[0] )
3135  {
3136  case 'A': // Arc
3137  aPart->AddDrawItem( loadArc( aPart, aReader ) );
3138  break;
3139 
3140  case 'C': // Circle
3141  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
3142  break;
3143 
3144  case 'T': // Text
3145  aPart->AddDrawItem( loadText( aPart, aReader, aMajorVersion, aMinorVersion ) );
3146  break;
3147 
3148  case 'S': // Square
3149  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
3150  break;
3151 
3152  case 'X': // Pin Description
3153  aPart->AddDrawItem( loadPin( aPart, aReader ) );
3154  break;
3155 
3156  case 'P': // Polyline
3157  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
3158  break;
3159 
3160  case 'B': // Bezier Curves
3161  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
3162  break;
3163 
3164  case '#': // Comment
3165  case '\n': // Empty line
3166  case '\r':
3167  case 0:
3168  break;
3169 
3170  default:
3171  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3172  }
3173 
3174  line = aReader.ReadLine();
3175  }
3176 
3177  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
3178 }
static LIB_POLYLINE * loadPolyLine(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_TEXT * loadText(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static LIB_CIRCLE * loadCircle(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_RECTANGLE * loadRectangle(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_BEZIER * loadBezier(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_ARC * loadArc(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)

References LINE_READER::Line(), loadArc(), loadBezier(), loadCircle(), loadPin(), loadPolyLine(), loadRectangle(), loadText(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by LoadPart().

◆ loadField()

void SCH_LEGACY_PLUGIN_CACHE::loadField ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 2970 of file sch_legacy_plugin.cpp.

2972 {
2973  const char* line = aReader.Line();
2974 
2975  wxCHECK_RET( *line == 'F', "Invalid field line" );
2976 
2977  wxString text;
2978  int id;
2979 
2980  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2981  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2982 
2983  LIB_FIELD* field;
2984 
2985  if( (unsigned) id < MANDATORY_FIELDS )
2986  {
2987  field = aPart->GetField( id );
2988 
2989  // this will fire only if somebody broke a constructor or editor.
2990  // MANDATORY_FIELDS are always present in ram resident components, no
2991  // exceptions, and they always have their names set, even fixed fields.
2992  wxASSERT( field );
2993  }
2994  else
2995  {
2996  field = new LIB_FIELD( aPart.get(), id );
2997  aPart->AddDrawItem( field );
2998  }
2999 
3000  // Skip to the first double quote.
3001  while( *line != '"' && *line != 0 )
3002  line++;
3003 
3004  if( *line == 0 )
3005  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
3006 
3007  parseQuotedString( text, aReader, line, &line, true );
3008 
3009  field->SetText( text );
3010 
3011  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
3012  // not save like this.
3013  if( text.size() == 1 && text[0] == '~' )
3014  field->SetText( wxEmptyString );
3015  else
3016  field->SetText( text );
3017 
3018  wxPoint pos;
3019 
3020  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3021  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3022  field->SetPosition( pos );
3023 
3024  wxSize textSize;
3025 
3026  textSize.x = textSize.y = Mils2Iu( parseInt( aReader, line, &line ) );
3027  field->SetTextSize( textSize );
3028 
3029  char textOrient = parseChar( aReader, line, &line );
3030 
3031  if( textOrient == 'H' )
3032  field->SetTextAngle( TEXT_ANGLE_HORIZ );
3033  else if( textOrient == 'V' )
3034  field->SetTextAngle( TEXT_ANGLE_VERT );
3035  else
3036  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
3037 
3038  char textVisible = parseChar( aReader, line, &line );
3039 
3040  if( textVisible == 'V' )
3041  field->SetVisible( true );
3042  else if ( textVisible == 'I' )
3043  field->SetVisible( false );
3044  else
3045  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
3046 
3047  // It may be technically correct to use the library version to determine if the field text
3048  // attributes are present. If anyone knows if that is valid and what version that would be,
3049  // please change this to test the library version rather than an EOL or the quoted string
3050  // of the field name.
3051  if( *line != 0 && *line != '"' )
3052  {
3053  char textHJustify = parseChar( aReader, line, &line );
3054 
3055  if( textHJustify == 'C' )
3057  else if( textHJustify == 'L' )
3059  else if( textHJustify == 'R' )
3061  else
3062  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
3063 
3064  wxString attributes;
3065 
3066  parseUnquotedString( attributes, aReader, line, &line );
3067 
3068  size_t attrSize = attributes.size();
3069 
3070  if( !(attrSize == 3 || attrSize == 1 ) )
3071  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
3072 
3073  switch( (wxChar) attributes[0] )
3074  {
3075  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3076  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3077  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3078  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
3079  }
3080 
3081  if( attrSize == 3 )
3082  {
3083  wxChar attr_1 = attributes[1];
3084  wxChar attr_2 = attributes[2];
3085 
3086  if( attr_1 == 'I' ) // Italic
3087  field->SetItalic( true );
3088  else if( attr_1 != 'N' ) // No italics is default, check for error.
3089  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
3090 
3091  if ( attr_2 == 'B' ) // Bold
3092  field->SetBold( true );
3093  else if( attr_2 != 'N' ) // No bold is default, check for error.
3094  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
3095  }
3096  }
3097 
3098  // Fields in RAM must always have names.
3099  if( (unsigned) id < MANDATORY_FIELDS )
3100  {
3101  // Fields in RAM must always have names, because we are trying to get
3102  // less dependent on field ids and more dependent on names.
3103  // Plus assumptions are made in the field editors.
3105 
3106  // Ensure the VALUE field = the part name (can be not the case
3107  // with malformed libraries: edited by hand, or converted from other tools)
3108  if( id == VALUE )
3109  field->SetText( aPart->GetName() );
3110  }
3111  else
3112  {
3113  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
3114  }
3115 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
#define TEXT_ANGLE_HORIZ
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:260
#define TEXT_ANGLE_VERT
void SetItalic(bool isItalic)
Definition: eda_text.h:163
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:169
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define Mils2Iu(x)
#define VALUE
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:187
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:186
#define _(s)
Definition: 3d_actions.cpp:33
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void SetBold(bool aBold)
Definition: eda_text.h:166

References _, TEMPLATE_FIELDNAME::GetDefaultFieldName(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, LINE_READER::Line(), LIB_FIELD::m_name, MANDATORY_FIELDS, Mils2Iu, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, EDA_TEXT::SetBold(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, VALUE, wxPoint::x, and wxPoint::y.

Referenced by LoadPart().

◆ loadFootprintFilters()

void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3705 of file sch_legacy_plugin.cpp.

3707 {
3708  const char* line = aReader.Line();
3709 
3710  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3711 
3712  line = aReader.ReadLine();
3713 
3714  wxArrayString footprintFilters;
3715 
3716  while( line )
3717  {
3718  if( strCompare( "$ENDFPLIST", line, &line ) )
3719  {
3720  aPart->SetFootprintFilters( footprintFilters );
3721  return;
3722  }
3723 
3724  wxString footprint;
3725 
3726  parseUnquotedString( footprint, aReader, line, &line );
3727  footprintFilters.Add( footprint );
3728  line = aReader.ReadLine();
3729  }
3730 
3731  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3732 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), parseUnquotedString(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by LoadPart().

◆ loadHeader()

void SCH_LEGACY_PLUGIN_CACHE::loadHeader ( FILE_LINE_READER aReader)
private

Definition at line 2745 of file sch_legacy_plugin.cpp.

2746 {
2747  const char* line = aReader.Line();
2748 
2749  wxASSERT( strCompare( "$HEADER", line, &line ) );
2750 
2751  while( aReader.ReadLine() )
2752  {
2753  line = (char*) aReader;
2754 
2755  // The time stamp saved in old library files is not used or saved in the latest
2756  // library file version.
2757  if( strCompare( "TimeStamp", line, &line ) )
2758  continue;
2759  else if( strCompare( "$ENDHEADER", line, &line ) )
2760  return;
2761  }
2762 
2763  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2764 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by Load().

◆ LoadPart()

LIB_PART * SCH_LEGACY_PLUGIN_CACHE::LoadPart ( LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion,
LIB_PART_MAP aMap = nullptr 
)
static

Definition at line 2767 of file sch_legacy_plugin.cpp.

2769 {
2770  const char* line = aReader.Line();
2771 
2772  while( *line == '#' )
2773  aReader.ReadLine();
2774 
2775  if( !strCompare( "DEF", line, &line ) )
2776  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2777 
2778  long num;
2779  size_t pos = 4; // "DEF" plus the first space.
2780  wxString utf8Line = wxString::FromUTF8( line );
2781  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2782 
2783  if( tokens.CountTokens() < 8 )
2784  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2785 
2786  // Read DEF line:
2787  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2788 
2789  wxString name, prefix, tmp;
2790 
2791  name = tokens.GetNextToken();
2792  pos += name.size() + 1;
2793 
2794  prefix = tokens.GetNextToken();
2795  pos += prefix.size() + 1;
2796 
2797  tmp = tokens.GetNextToken();
2798  pos += tmp.size() + 1; // NumOfPins, unused.
2799 
2800  tmp = tokens.GetNextToken(); // Pin name offset.
2801 
2802  if( !tmp.ToLong( &num ) )
2803  THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
2804  aReader.LineNumber(), pos );
2805 
2806  pos += tmp.size() + 1;
2807  part->SetPinNameOffset( Mils2Iu( (int)num ) );
2808 
2809  tmp = tokens.GetNextToken(); // Show pin numbers.
2810 
2811  if( !( tmp == "Y" || tmp == "N") )
2812  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2813  aReader.LineNumber(), pos );
2814 
2815  pos += tmp.size() + 1;
2816  part->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
2817 
2818  tmp = tokens.GetNextToken(); // Show pin names.
2819 
2820  if( !( tmp == "Y" || tmp == "N") )
2821  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2822  aReader.LineNumber(), pos );
2823 
2824  pos += tmp.size() + 1;
2825  part->SetShowPinNames( ( tmp == "N" ) ? false : true );
2826 
2827  tmp = tokens.GetNextToken(); // Number of units.
2828 
2829  if( !tmp.ToLong( &num ) )
2830  THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
2831  aReader.LineNumber(), pos );
2832 
2833  pos += tmp.size() + 1;
2834  part->SetUnitCount( (int)num );
2835 
2836  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2837  if( part->GetUnitCount() < 1 )
2838  part->SetUnitCount( 1 );
2839 
2840  // Copy part name and prefix.
2841 
2842  // The root alias is added to the alias list by SetName() which is called by SetText().
2843  if( name.IsEmpty() )
2844  {
2845  part->SetName( "~" );
2846  }
2847  else if( name[0] != '~' )
2848  {
2849  part->SetName( name );
2850  }
2851  else
2852  {
2853  part->SetName( name.Right( name.Length() - 1 ) );
2854  part->GetValueField().SetVisible( false );
2855  }
2856 
2857  // Don't set the library alias, this is determined by the symbol library table.
2858  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2859 
2860  LIB_FIELD& reference = part->GetReferenceField();
2861 
2862  if( prefix == "~" )
2863  {
2864  reference.Empty();
2865  reference.SetVisible( false );
2866  }
2867  else
2868  {
2869  reference.SetText( prefix );
2870  }
2871 
2872  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2873  // The was no concept of interchangeable multiple unit symbols.
2874  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
2875  && LIB_VERSION( aMajorVersion, aMinorVersion ) <= LIB_VERSION( 2, 2 ) )
2876  {
2877  // Nothing needs to be set since the default setting for symbols with multiple
2878  // units were never interchangeable. Just parse the 0 an move on.
2879  tmp = tokens.GetNextToken();
2880  pos += tmp.size() + 1;
2881  }
2882  else
2883  {
2884  tmp = tokens.GetNextToken();
2885 
2886  if( tmp == "L" )
2887  part->LockUnits( true );
2888  else if( tmp == "F" || tmp == "0" )
2889  part->LockUnits( false );
2890  else
2891  THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
2892  aReader.LineNumber(), pos );
2893 
2894  pos += tmp.size() + 1;
2895  }
2896 
2897  // There is the optional power component flag.
2898  if( tokens.HasMoreTokens() )
2899  {
2900  tmp = tokens.GetNextToken();
2901 
2902  if( tmp == "P" )
2903  part->SetPower();
2904  else if( tmp == "N" )
2905  part->SetNormal();
2906  else
2907  THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
2908  aReader.LineNumber(), pos );
2909  }
2910 
2911  line = aReader.ReadLine();
2912 
2913  // Read lines until "ENDDEF" is found.
2914  while( line )
2915  {
2916  if( *line == '#' ) // Comment
2917  ;
2918  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2919  continue;
2920  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2921  loadAliases( part, aReader, aMap );
2922  else if( *line == 'F' ) // Fields
2923  loadField( part, aReader );
2924  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2925  loadDrawEntries( part, aReader, aMajorVersion, aMinorVersion );
2926  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2927  loadFootprintFilters( part, aReader );
2928  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2929  {
2930  return part.release();
2931  }
2932 
2933  line = aReader.ReadLine();
2934  }
2935 
2936  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2937 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
static void loadDrawEntries(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:169
#define LIB_VERSION(major, minor)
Definition: class_library.h:60
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
#define Mils2Iu(x)
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
static void loadField(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
void Empty()
Definition: eda_text.h:239
Define a library symbol object.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
static void loadAliases(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, LIB_PART_MAP *aMap=nullptr)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static void loadFootprintFilters(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
const char * name
Definition: DXF_plotter.cpp:60
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References EDA_TEXT::Empty(), LINE_READER::GetSource(), LIB_VERSION, LINE_READER::Line(), LINE_READER::LineNumber(), loadAliases(), loadDrawEntries(), loadField(), loadFootprintFilters(), Mils2Iu, name, LINE_READER::ReadLine(), SCH_PARSE_ERROR, EDA_TEXT::SetText(), EDA_TEXT::SetVisible(), strCompare(), and THROW_PARSE_ERROR.

Referenced by Load(), and SCH_LEGACY_PLUGIN::ParsePart().

◆ loadPin()

LIB_PIN * SCH_LEGACY_PLUGIN_CACHE::loadPin ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3419 of file sch_legacy_plugin.cpp.

3421 {
3422  const char* line = aReader.Line();
3423 
3424  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3425 
3426  LIB_PIN* pin = new LIB_PIN( aPart.get() );
3427 
3428  size_t pos = 2; // "X" plus ' ' space character.
3429  wxString tmp;
3430  wxString utf8Line = wxString::FromUTF8( line );
3431  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3432 
3433  if( tokens.CountTokens() < 11 )
3434  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3435 
3436  pin->m_name = tokens.GetNextToken();
3437  pos += pin->m_name.size() + 1;
3438  pin->m_number = tokens.GetNextToken();
3439  pos += pin->m_number.size() + 1;
3440 
3441  long num;
3442  wxPoint position;
3443 
3444  tmp = tokens.GetNextToken();
3445 
3446  if( !tmp.ToLong( &num ) )
3447  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3448  aReader.LineNumber(), pos );
3449 
3450  pos += tmp.size() + 1;
3451  position.x = Mils2Iu( (int) num );
3452 
3453  tmp = tokens.GetNextToken();
3454 
3455  if( !tmp.ToLong( &num ) )
3456  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3457  aReader.LineNumber(), pos );
3458 
3459  pos += tmp.size() + 1;
3460  position.y = Mils2Iu( (int) num );
3461  pin->m_position = position;
3462 
3463  tmp = tokens.GetNextToken();
3464 
3465  if( !tmp.ToLong( &num ) )
3466  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3467  aReader.LineNumber(), pos );
3468 
3469  pos += tmp.size() + 1;
3470  pin->m_length = Mils2Iu( (int) num );
3471 
3472 
3473  tmp = tokens.GetNextToken();
3474 
3475  if( tmp.size() > 1 )
3476  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3477  aReader.LineNumber(), pos );
3478 
3479  pos += tmp.size() + 1;
3480  pin->m_orientation = tmp[0];
3481 
3482  tmp = tokens.GetNextToken();
3483 
3484  if( !tmp.ToLong( &num ) )
3485  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3486  aReader.LineNumber(), pos );
3487 
3488  pos += tmp.size() + 1;
3489  pin->m_numTextSize = Mils2Iu( (int) num );
3490 
3491  tmp = tokens.GetNextToken();
3492 
3493  if( !tmp.ToLong( &num ) )
3494  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3495  aReader.LineNumber(), pos );
3496 
3497  pos += tmp.size() + 1;
3498  pin->m_nameTextSize = Mils2Iu( (int) num );
3499 
3500  tmp = tokens.GetNextToken();
3501 
3502  if( !tmp.ToLong( &num ) )
3503  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3504  aReader.LineNumber(), pos );
3505 
3506  pos += tmp.size() + 1;
3507  pin->m_Unit = (int) num;
3508 
3509  tmp = tokens.GetNextToken();
3510 
3511  if( !tmp.ToLong( &num ) )
3512  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3513  aReader.LineNumber(), pos );
3514 
3515  pos += tmp.size() + 1;
3516  pin->m_Convert = (int) num;
3517 
3518  tmp = tokens.GetNextToken();
3519 
3520  if( tmp.size() != 1 )
3521  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3522  aReader.LineNumber(), pos );
3523 
3524  pos += tmp.size() + 1;
3525  char type = tmp[0];
3526 
3527  wxString attributes;
3528 
3529  switch( type )
3530  {
3531  case 'I':
3533  break;
3534  case 'O':
3536  break;
3537  case 'B':
3539  break;
3540  case 'T':
3542  break;
3543  case 'P':
3545  break;
3546  case 'U':
3548  break;
3549  case 'W':
3551  break;
3552  case 'w':
3554  break;
3555  case 'C':
3557  break;
3558  case 'E':
3560  break;
3561  case 'N':
3563  break;
3564  default:
3565  THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(), aReader.Line(),
3566  aReader.LineNumber(), pos );
3567  }
3568 
3569  // Optional
3570  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3571  {
3572  tmp = tokens.GetNextToken();
3573 
3574  enum
3575  {
3576  INVERTED = 1 << 0,
3577  CLOCK = 1 << 1,
3578  LOWLEVEL_IN = 1 << 2,
3579  LOWLEVEL_OUT = 1 << 3,
3580  FALLING_EDGE = 1 << 4,
3581  NONLOGIC = 1 << 5
3582  };
3583 
3584  int flags = 0;
3585 
3586  for( int j = tmp.size(); j > 0; )
3587  {
3588  switch( tmp[--j].GetValue() )
3589  {
3590  case '~': break;
3591  case 'N': pin->m_attributes |= PIN_INVISIBLE; break;
3592  case 'I': flags |= INVERTED; break;
3593  case 'C': flags |= CLOCK; break;
3594  case 'L': flags |= LOWLEVEL_IN; break;
3595  case 'V': flags |= LOWLEVEL_OUT; break;
3596  case 'F': flags |= FALLING_EDGE; break;
3597  case 'X': flags |= NONLOGIC; break;
3598  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3599  aReader.Line(), aReader.LineNumber(), pos );
3600  }
3601 
3602  pos += 1;
3603  }
3604 
3605  switch( flags )
3606  {
3607  case 0:
3609  break;
3610  case INVERTED:
3612  break;
3613  case CLOCK:
3615  break;
3616  case INVERTED | CLOCK:
3618  break;
3619  case LOWLEVEL_IN:
3621  break;
3622  case LOWLEVEL_IN | CLOCK:
3624  break;
3625  case LOWLEVEL_OUT:
3627  break;
3628  case FALLING_EDGE:
3630  break;
3631  case NONLOGIC:
3633  break;
3634  default:
3635  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3636  }
3637  }
3638 
3639  return pin;
3640 }
power input (GND, VCC for ICs). Must be connected to a power output.
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:80
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:73
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
int m_numTextSize
Definition: lib_pin.h:79
pin for passive components: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:81
wxString m_name
Definition: lib_pin.h:77
int m_length
Length of the pin.
Definition: lib_pin.h:71
std::chrono::steady_clock CLOCK
#define Mils2Iu(x)
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:72
wxString m_number
Definition: lib_pin.h:78
#define NULL
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
#define PIN_INVISIBLE
Definition: lib_pin.h:49
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:76
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:70
#define SCH_PARSE_ERROR(text, reader, pos)
usual pin input: must be connected
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:75
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
int m_Convert
Shape identification for alternate body styles.
Definition: lib_item.h:87
input or output (like port for a microprocessor)
not connected (must be left open)
output of a regulator: intended to be connected to power input pins

References CLOCK, CLOCK_LOW, FALLING_EDGE_CLOCK, LINE_READER::GetSource(), INPUT_LOW, INVERTED, INVERTED_CLOCK, LINE, LINE_READER::Line(), LINE_READER::LineNumber(), LIB_PIN::m_attributes, LIB_ITEM::m_Convert, LIB_PIN::m_length, LIB_PIN::m_name, LIB_PIN::m_nameTextSize, LIB_PIN::m_number, LIB_PIN::m_numTextSize, LIB_PIN::m_orientation, LIB_PIN::m_position, LIB_PIN::m_shape, LIB_PIN::m_type, LIB_ITEM::m_Unit, Mils2Iu, NONLOGIC, NULL, OUTPUT_LOW, PIN_INVISIBLE, PT_BIDI, PT_INPUT, PT_NC, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_POWER_OUT, PT_TRISTATE, PT_UNSPECIFIED, SCH_PARSE_ERROR, strCompare(), THROW_PARSE_ERROR, wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadPolyLine()

LIB_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3643 of file sch_legacy_plugin.cpp.

3645 {
3646  const char* line = aReader.Line();
3647 
3648  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3649 
3650  LIB_POLYLINE* polyLine = new LIB_POLYLINE( aPart.get() );
3651 
3652  int points = parseInt( aReader, line, &line );
3653  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3654  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3655  polyLine->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3656  polyLine->Reserve( points );
3657 
3658  wxPoint pt;
3659 
3660  for( int i = 0; i < points; i++ )
3661  {
3662  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3663  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3664  polyLine->AddPoint( pt );
3665  }
3666 
3667  if( *line != 0 )
3668  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3669 
3670  return polyLine;
3671 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetWidth(int aWidth) override
Definition: lib_polyline.h:105
#define Mils2Iu(x)
#define NULL
void Reserve(size_t aPointCount)
Definition: lib_polyline.h:57
void AddPoint(const wxPoint &aPoint)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:314
void SetConvert(int aConvert)
Definition: lib_item.h:311
void SetUnit(int aUnit)
Definition: lib_item.h:308
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LIB_POLYLINE::AddPoint(), LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_POLYLINE::Reserve(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetUnit(), LIB_POLYLINE::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadRectangle()

LIB_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3387 of file sch_legacy_plugin.cpp.

3389 {
3390  const char* line = aReader.Line();
3391 
3392  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3393 
3394  LIB_RECTANGLE* rectangle = new LIB_RECTANGLE( aPart.get() );
3395 
3396  wxPoint pos;
3397 
3398  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3399  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3400  rectangle->SetPosition( pos );
3401 
3402  wxPoint end;
3403 
3404  end.x = Mils2Iu( parseInt( aReader, line, &line ) );
3405  end.y = Mils2Iu( parseInt( aReader, line, &line ) );
3406  rectangle->SetEnd( end );
3407 
3408  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3409  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3410  rectangle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3411 
3412  if( *line != 0 )
3413  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3414 
3415  return rectangle;
3416 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:260
#define Mils2Iu(x)
#define NULL
void SetWidth(int aWidth) override
Definition: lib_rectangle.h:86
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:314
void SetConvert(int aConvert)
Definition: lib_item.h:311
void SetUnit(int aUnit)
Definition: lib_item.h:308
void SetEnd(const wxPoint &aEnd)
Definition: lib_rectangle.h:88
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_ITEM::SetConvert(), LIB_RECTANGLE::SetEnd(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetPosition(), LIB_ITEM::SetUnit(), LIB_RECTANGLE::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadText()

LIB_TEXT * SCH_LEGACY_PLUGIN_CACHE::loadText ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion 
)
staticprivate

Definition at line 3294 of file sch_legacy_plugin.cpp.

3298 {
3299  const char* line = aReader.Line();
3300 
3301  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3302 
3303  LIB_TEXT* text = new LIB_TEXT( aPart.get() );
3304 
3305  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3306 
3307  wxPoint center;
3308 
3309  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3310  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3311  text->SetPosition( center );
3312 
3313  wxSize size;
3314 
3315  size.x = size.y = Mils2Iu( parseInt( aReader, line, &line ) );
3316  text->SetTextSize( size );
3317  text->SetVisible( !parseInt( aReader, line, &line ) );
3318  text->SetUnit( parseInt( aReader, line, &line ) );
3319  text->SetConvert( parseInt( aReader, line, &line ) );
3320 
3321  wxString str;
3322 
3323  // If quoted string loading fails, load as not quoted string.
3324  if( *line == '"' )
3325  parseQuotedString( str, aReader, line, &line );
3326  else
3327  {
3328  parseUnquotedString( str, aReader, line, &line );
3329 
3330  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3331  str.Replace( "~", " " );
3332  }
3333 
3334  if( !str.IsEmpty() )
3335  {
3336  // convert two apostrophes back to double quote
3337  str.Replace( "''", "\"" );
3338  }
3339 
3340  text->SetText( str );
3341 
3342  // Here things are murky and not well defined. At some point it appears the format
3343  // was changed to add text properties. However rather than add the token to the end of
3344  // the text definition, it was added after the string and no mention if the file
3345  // verion was bumped or not so this code make break on very old component libraries.
3346  //
3347  // Update: apparently even in the latest version this can be different so added a test
3348  // for end of line before checking for the text properties.
3349  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
3350  && LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3351  {
3352  if( strCompare( "Italic", line, &line ) )
3353  text->SetItalic( true );
3354  else if( !strCompare( "Normal", line, &line ) )
3355  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3356 
3357  if( parseInt( aReader, line, &line ) > 0 )
3358  text->SetBold( true );
3359 
3360  // Some old libaries version > 2.0 do not have these options for text justification:
3361  if( !is_eol( *line ) )
3362  {
3363  switch( parseChar( aReader, line, &line ) )
3364  {
3365  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3366  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3367  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3368  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3369  aReader, line );
3370  }
3371 
3372  switch( parseChar( aReader, line, &line ) )
3373  {
3374  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3375  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3376  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3377  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3378  aReader, line );
3379  }
3380  }
3381  }
3382 
3383  return text;
3384 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:260
Define a symbol library graphical text item.
Definition: lib_text.h:40
void SetItalic(bool isItalic)
Definition: eda_text.h:163
void SetVisible(bool aVisible)
Definition: eda_text.h:169
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define LIB_VERSION(major, minor)
Definition: class_library.h:60
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define Mils2Iu(x)
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:111
#define NULL
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:187
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static bool is_eol(char c)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetConvert(int aConvert)
Definition: lib_item.h:311
void SetUnit(int aUnit)
Definition: lib_item.h:308
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:186
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetBold(bool aBold)
Definition: eda_text.h:166

References GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, is_eol(), LIB_VERSION, LINE_READER::Line(), Mils2Iu, NULL, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, EDA_TEXT::SetBold(), LIB_ITEM::SetConvert(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextSize(), LIB_ITEM::SetUnit(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ parseFillMode()

FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode ( LINE_READER aReader,
const char *  aLine,
const char **  aOutput 
)
staticprivate

Definition at line 3181 of file sch_legacy_plugin.cpp.

3183 {
3184  switch ( parseChar( aReader, aLine, aOutput ) )
3185  {
3186  case 'F':
3187  return FILLED_SHAPE;
3188  case 'f':
3189  return FILLED_WITH_BG_BODYCOLOR;
3190  case 'N':
3191  return NO_FILL;
3192  default:
3193  SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3194  }
3195 
3196  // This will never be reached but quiets the compiler warnings
3197  return NO_FILL;
3198 }
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define SCH_PARSE_ERROR(text, reader, pos)

References FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR, NO_FILL, parseChar(), and SCH_PARSE_ERROR.

Referenced by loadArc(), loadBezier(), loadCircle(), loadPolyLine(), and loadRectangle().

◆ removeSymbol()

LIB_PART * SCH_LEGACY_PLUGIN_CACHE::removeSymbol ( LIB_PART aAlias)
private

Definition at line 2471 of file sch_legacy_plugin.cpp.

2472 {
2473  wxCHECK_MSG( aPart != NULL, NULL, "NULL pointer cannot be removed from library." );
2474 
2475  LIB_PART* firstChild = NULL;
2476  LIB_PART_MAP::iterator it = m_symbols.find( aPart->GetName() );
2477 
2478  if( it == m_symbols.end() )
2479  return NULL;
2480 
2481  // If the entry pointer doesn't match the name it is mapped to in the library, we
2482  // have done something terribly wrong.
2483  wxCHECK_MSG( *it->second == aPart, NULL,
2484  "Pointer mismatch while attempting to remove alias entry <" + aPart->GetName() +
2485  "> from library cache <" + m_libFileName.GetName() + ">." );
2486 
2487  // If the symbol is a root symbol used by other symbols find the first alias that uses
2488  // the root part and make it the new root.
2489  if( aPart->IsRoot() )
2490  {
2491  for( auto entry : m_symbols )
2492  {
2493  if( entry.second->IsAlias()
2494  && entry.second->GetParent().lock() == aPart->SharedPtr() )
2495  {
2496  firstChild = entry.second;
2497  break;
2498  }
2499  }
2500 
2501  if( firstChild )
2502  {
2503  for( LIB_ITEM& drawItem : aPart->GetDrawItems() )
2504  {
2505  if( drawItem.Type() == LIB_FIELD_T )
2506  {
2507  LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
2508 
2509  if( firstChild->FindField( field.GetName( NATIVE_FIELD_NAME ) ) )
2510  continue;
2511  }
2512 
2513  LIB_ITEM* newItem = (LIB_ITEM*) drawItem.Clone();
2514  drawItem.SetParent( firstChild );
2515  firstChild->AddDrawItem( newItem );
2516  }
2517 
2518  // Reparent the remaining aliases.
2519  for( auto entry : m_symbols )
2520  {
2521  if( entry.second->IsAlias()
2522  && entry.second->GetParent().lock() == aPart->SharedPtr() )
2523  entry.second->SetParent( firstChild );
2524  }
2525  }
2526  }
2527 
2528  m_symbols.erase( it );
2529  delete aPart;
2530  m_isModified = true;
2531  ++m_modHash;
2532  return firstChild;
2533 }
Field object used in symbol libraries.
Definition: lib_field.h:59
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:60
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this part matching aFieldName and returns it or NULL if not found.
#define NULL
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:218
Define a library symbol object.
wxString GetName(bool aTranslate) const
Definition: lib_field.cpp:387
#define NATIVE_FIELD_NAME
Definition: lib_field.h:125

References LIB_PART::AddDrawItem(), EDA_ITEM::Clone(), LIB_PART::FindField(), LIB_PART::GetDrawItems(), LIB_FIELD::GetName(), LIB_PART::GetName(), LIB_PART::IsRoot(), LIB_FIELD_T, m_isModified, m_libFileName, m_modHash, m_symbols, NATIVE_FIELD_NAME, NULL, EDA_ITEM::SetParent(), and LIB_PART::SharedPtr().

Referenced by AddSymbol().

◆ Save()

void SCH_LEGACY_PLUGIN_CACHE::Save ( bool  aSaveDocFile = true)

Save the entire library to file m_libFileName;.

Definition at line 3735 of file sch_legacy_plugin.cpp.

3736 {
3737  if( !m_isModified )
3738  return;
3739 
3740  // Write through symlinks, don't replace them
3741  wxFileName fn = GetRealFile();
3742 
3743  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) );
3744  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3745  formatter->Print( 0, "#encoding utf-8\n");
3746 
3747  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); it++ )
3748  {
3749  if( !it->second->IsRoot() )
3750  continue;
3751 
3752  SaveSymbol( it->second, *formatter.get(), &m_symbols );
3753  }
3754 
3755  formatter->Print( 0, "#\n#End Library\n" );
3756  formatter.reset();
3757 
3758  m_fileModTime = fn.GetModificationTime();
3759  m_isModified = false;
3760 
3761  if( aSaveDocFile )
3762  saveDocFile();
3763 }
#define LIBFILE_IDENT
Definition: class_library.h:58
#define LIB_VERSION_MINOR
Definition: class_library.h:55
#define LIB_VERSION_MAJOR
Definition: class_library.h:54
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_PART_MAP *aMap=nullptr)
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
wxFileName GetRealFile() const

References GetRealFile(), LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIBFILE_IDENT, m_fileModTime, m_isModified, m_symbols, saveDocFile(), and SaveSymbol().

Referenced by SCH_LEGACY_PLUGIN::CreateSymbolLib(), SCH_LEGACY_PLUGIN::DeleteSymbol(), SCH_LEGACY_PLUGIN::SaveLibrary(), and SCH_LEGACY_PLUGIN::SaveSymbol().

◆ saveArc()

void SCH_LEGACY_PLUGIN_CACHE::saveArc ( LIB_ARC aArc,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3939 of file sch_legacy_plugin.cpp.

3941 {
3942  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3943 
3944  int x1 = aArc->GetFirstRadiusAngle();
3945 
3946  if( x1 > 1800 )
3947  x1 -= 3600;
3948 
3949  int x2 = aArc->GetSecondRadiusAngle();
3950 
3951  if( x2 > 1800 )
3952  x2 -= 3600;
3953 
3954  aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3955  Iu2Mils( aArc->GetPosition().x ), Iu2Mils( aArc->GetPosition().y ),
3956  Iu2Mils( aArc->GetRadius() ), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3957  Iu2Mils( aArc->GetWidth() ), fill_tab[aArc->GetFillMode()],
3958  Iu2Mils( aArc->GetStart().x ), Iu2Mils( aArc->GetStart().y ),
3959  Iu2Mils( aArc->GetEnd().x ), Iu2Mils( aArc->GetEnd().y ) );
3960 }
FILL_T GetFillMode() const
Definition: lib_item.h:315
int GetSecondRadiusAngle() const
Definition: lib_arc.h:111
int GetUnit() const
Definition: lib_item.h:309
wxPoint GetStart() const
Definition: lib_arc.h:113
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:312
int GetRadius() const
Definition: lib_arc.h:105
int GetWidth() const override
Definition: lib_arc.h:101
wxPoint GetEnd() const
Definition: lib_arc.h:116
int GetFirstRadiusAngle() const
Definition: lib_arc.h:108
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
wxPoint GetPosition() const override
Definition: lib_arc.h:92

References fill_tab, LIB_ITEM::GetConvert(), LIB_ARC::GetEnd(), LIB_ITEM::GetFillMode(), LIB_ARC::GetFirstRadiusAngle(), LIB_ARC::GetPosition(), LIB_ARC::GetRadius(), LIB_ARC::GetSecondRadiusAngle(), LIB_ARC::GetStart(), LIB_ITEM::GetUnit(), LIB_ARC::GetWidth(), LIB_ARC_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ saveBezier()

void SCH_LEGACY_PLUGIN_CACHE::saveBezier ( LIB_BEZIER aBezier,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3963 of file sch_legacy_plugin.cpp.

3965 {
3966  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3967 
3968  aFormatter.Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3969  aBezier->GetUnit(), aBezier->GetConvert(), Iu2Mils( aBezier->GetWidth() ) );
3970 
3971  for( const auto& pt : aBezier->GetPoints() )
3972  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
3973 
3974  aFormatter.Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3975 }
FILL_T GetFillMode() const
Definition: lib_item.h:315
int GetWidth() const override
Definition: lib_bezier.h:91
int GetUnit() const
Definition: lib_item.h:309
const int fill_tab[3]
Definition: lib_item.cpp:34
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:71
int GetConvert() const
Definition: lib_item.h:312
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References fill_tab, LIB_ITEM::GetConvert(), LIB_ITEM::GetFillMode(), LIB_BEZIER::GetPoints(), LIB_ITEM::GetUnit(), LIB_BEZIER::GetWidth(), LIB_BEZIER_T, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveCircle()

void SCH_LEGACY_PLUGIN_CACHE::saveCircle ( LIB_CIRCLE aCircle,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3978 of file sch_legacy_plugin.cpp.

3980 {
3981  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3982 
3983  aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n",
3984  Iu2Mils( aCircle->GetPosition().x ), Iu2Mils( aCircle->GetPosition().y ),
3985  Iu2Mils( aCircle->GetRadius() ), aCircle->GetUnit(), aCircle->GetConvert(),
3986  Iu2Mils( aCircle->GetWidth() ), fill_tab[aCircle->GetFillMode()] );
3987 }
FILL_T GetFillMode() const
Definition: lib_item.h:315
wxPoint GetPosition() const override
Definition: lib_circle.h:76
int GetWidth() const override
Definition: lib_circle.h:88
int GetUnit() const
Definition: lib_item.h:309
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetRadius() const
Definition: lib_circle.h:92
int GetConvert() const
Definition: lib_item.h:312
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References fill_tab, LIB_ITEM::GetConvert(), LIB_ITEM::GetFillMode(), LIB_CIRCLE::GetPosition(), LIB_CIRCLE::GetRadius(), LIB_ITEM::GetUnit(), LIB_CIRCLE::GetWidth(), LIB_CIRCLE_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ saveDocFile()

void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 4231 of file sch_legacy_plugin.cpp.

4232 {
4233  wxFileName fileName = m_libFileName;
4234 
4235  fileName.SetExt( DOC_EXT );
4236  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
4237 
4238  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
4239 
4240  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
4241  {
4242  wxString description = it->second->GetDescription();
4243  wxString keyWords = it->second->GetKeyWords();
4244  wxString docFileName = it->second->GetDocFileName();
4245 
4246  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
4247  continue;
4248 
4249  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
4250 
4251  if( !description.IsEmpty() )
4252  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
4253 
4254  if( !keyWords.IsEmpty() )
4255  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
4256 
4257  if( !docFileName.IsEmpty() )
4258  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
4259 
4260  formatter.Print( 0, "$ENDCMP\n" );
4261  }
4262 
4263  formatter.Print( 0, "#\n#End Doc Library\n" );
4264 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:49
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References DOC_EXT, DOCFILE_IDENT, m_libFileName, m_symbols, OUTPUTFORMATTER::Print(), and TO_UTF8.

Referenced by Save().

◆ saveField()

void SCH_LEGACY_PLUGIN_CACHE::saveField ( LIB_FIELD aField,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3990 of file sch_legacy_plugin.cpp.

3992 {
3993  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3994 
3995  int hjustify, vjustify;
3996  int id = aField->GetId();
3997  wxString text = aField->GetText();
3998 
3999  hjustify = 'C';
4000 
4001  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4002  hjustify = 'L';
4003  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4004  hjustify = 'R';
4005 
4006  vjustify = 'C';
4007 
4008  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4009  vjustify = 'B';
4010  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4011  vjustify = 'T';
4012 
4013  aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
4014  id,
4015  EscapedUTF8( text ).c_str(), // wraps in quotes
4016  Iu2Mils( aField->GetTextPos().x ), Iu2Mils( aField->GetTextPos().y ),
4017  Iu2Mils( aField->GetTextWidth() ),
4018  aField->GetTextAngle() == 0 ? 'H' : 'V',
4019  aField->IsVisible() ? 'V' : 'I',
4020  hjustify, vjustify,
4021  aField->IsItalic() ? 'I' : 'N',
4022  aField->IsBold() ? 'B' : 'N' );
4023 
4024  /* Save field name, if necessary
4025  * Field name is saved only if it is not the default name.
4026  * Just because default name depends on the language and can change from
4027  * a country to another
4028  */
4029  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
4030 
4031  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
4032  aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
4033 
4034  aFormatter.Print( 0, "\n" );
4035 }
bool IsBold() const
Definition: eda_text.h:167
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:184
bool IsVisible() const
Definition: eda_text.h:170
double GetTextAngle() const
Definition: eda_text.h:158
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
int GetId() const
Definition: lib_field.h:139
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249
bool IsItalic() const
Definition: eda_text.h:164
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
int GetTextWidth() const
Definition: eda_text.h:226
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References EscapedUTF8(), FIELD1, TEMPLATE_FIELDNAME::GetDefaultFieldName(), EDA_TEXT::GetHorizJustify(), LIB_FIELD::GetId(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextWidth(), EDA_TEXT::GetVertJustify(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsVisible(), LIB_FIELD_T, LIB_FIELD::m_name, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ savePin()

void SCH_LEGACY_PLUGIN_CACHE::savePin ( LIB_PIN aPin,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4038 of file sch_legacy_plugin.cpp.

4040 {
4041  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
4042 
4043  int Etype;
4044 
4045  switch( aPin->GetType() )
4046  {
4047  default:
4049  Etype = 'I';
4050  break;
4051 
4053  Etype = 'O';
4054  break;
4055 
4057  Etype = 'B';
4058  break;
4059 
4061  Etype = 'T';
4062  break;
4063 
4065  Etype = 'P';
4066  break;
4067 
4069  Etype = 'U';
4070  break;
4071 
4073  Etype = 'W';
4074  break;
4075 
4077  Etype = 'w';
4078  break;
4079 
4081  Etype = 'C';
4082  break;
4083 
4085  Etype = 'E';
4086  break;
4087 
4089  Etype = 'N';
4090  break;
4091  }
4092 
4093  if( !aPin->GetName().IsEmpty() )
4094  aFormatter.Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
4095  else
4096  aFormatter.Print( 0, "X ~" );
4097 
4098  aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
4099  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
4100  Iu2Mils( aPin->GetPosition().x ), Iu2Mils( aPin->GetPosition().y ),
4101  Iu2Mils( (int) aPin->GetLength() ), (int) aPin->GetOrientation(),
4102  Iu2Mils( aPin->GetNumberTextSize() ), Iu2Mils( aPin->GetNameTextSize() ),
4103  aPin->GetUnit(), aPin->GetConvert(), Etype );
4104 
4105  if( aPin->GetShape() != GRAPHIC_PINSHAPE::LINE || !aPin->IsVisible() )
4106  aFormatter.Print( 0, " " );
4107 
4108  if( !aPin->IsVisible() )
4109  aFormatter.Print( 0, "N" );
4110 
4111  switch( aPin->GetShape() )
4112  {
4114  break;
4115 
4117  aFormatter.Print( 0, "I" );
4118  break;
4119 
4121  aFormatter.Print( 0, "C" );
4122  break;
4123 
4125  aFormatter.Print( 0, "IC" );
4126  break;
4127 
4129  aFormatter.Print( 0, "L" );
4130  break;
4131 
4133  aFormatter.Print( 0, "CL" );
4134  break;
4135 
4137  aFormatter.Print( 0, "V" );
4138  break;
4139 
4141  aFormatter.Print( 0, "F" );
4142  break;
4143 
4145  aFormatter.Print( 0, "X" );
4146  break;
4147 
4148  default:
4149  assert( !"Invalid pin shape" );
4150  }
4151 
4152  aFormatter.Print( 0, "\n" );
4153 
4154  aPin->ClearFlags( IS_CHANGED );
4155 }
power input (GND, VCC for ICs). Must be connected to a power output.
int GetOrientation() const
Definition: lib_pin.h:207
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:219
pin for passive components: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
int GetUnit() const
Definition: lib_item.h:309
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:116
const wxString & GetName() const
Definition: lib_pin.h:152
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:346
int GetNameTextSize() const
Definition: lib_pin.h:178
int GetConvert() const
Definition: lib_item.h:312
wxPoint GetPosition() const override
Definition: lib_pin.h:432
const wxString & GetNumber() const
Definition: lib_pin.h:180
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:235
int GetNumberTextSize() const
Definition: lib_pin.h:205
usual pin input: must be connected
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:258
input or output (like port for a microprocessor)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
not connected (must be left open)
int GetLength()
Definition: lib_pin.h:285
output of a regulator: intended to be connected to power input pins
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References EDA_ITEM::ClearFlags(), CLOCK, CLOCK_LOW, FALLING_EDGE_CLOCK, LIB_ITEM::GetConvert(), LIB_PIN::GetLength(), LIB_PIN::GetName(), LIB_PIN::GetNameTextSize(), LIB_PIN::GetNumber(), LIB_PIN::GetNumberTextSize(), LIB_PIN::GetOrientation(), LIB_PIN::GetPosition(), LIB_PIN::GetShape(), LIB_PIN::GetType(), LIB_ITEM::GetUnit(), INPUT_LOW, INVERTED, INVERTED_CLOCK, IS_CHANGED, LIB_PIN::IsVisible(), LIB_PIN_T, LINE, NONLOGIC, OUTPUT_LOW, OUTPUTFORMATTER::Print(), PT_BIDI, PT_INPUT, PT_NC, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_POWER_OUT, PT_TRISTATE, PT_UNSPECIFIED, TO_UTF8, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ savePolyLine()

void SCH_LEGACY_PLUGIN_CACHE::savePolyLine ( LIB_POLYLINE aPolyLine,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4158 of file sch_legacy_plugin.cpp.

4160 {
4161  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
4162 
4163  int ccount = aPolyLine->GetCornerCount();
4164 
4165  aFormatter.Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
4166  Iu2Mils( aPolyLine->GetWidth() ) );
4167 
4168  for( const auto& pt : aPolyLine->GetPolyPoints() )
4169  {
4170  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
4171  }
4172 
4173  aFormatter.Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
4174 }
FILL_T GetFillMode() const
Definition: lib_item.h:315
int GetWidth() const override
Definition: lib_polyline.h:104
unsigned GetCornerCount() const
Definition: lib_polyline.h:73
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:60
int GetUnit() const
Definition: lib_item.h:309
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:312
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References fill_tab, LIB_ITEM::GetConvert(), LIB_POLYLINE::GetCornerCount(), LIB_ITEM::GetFillMode(), LIB_POLYLINE::GetPolyPoints(), LIB_ITEM::GetUnit(), LIB_POLYLINE::GetWidth(), LIB_POLYLINE_T, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveRectangle()

void SCH_LEGACY_PLUGIN_CACHE::saveRectangle ( LIB_RECTANGLE aRectangle,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4177 of file sch_legacy_plugin.cpp.

4179 {
4180  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
4181  "Invalid LIB_RECTANGLE object." );
4182 
4183  aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n",
4184  Iu2Mils( aRectangle->GetPosition().x ),
4185  Iu2Mils( aRectangle->GetPosition().y ),
4186  Iu2Mils( aRectangle->GetEnd().x ), Iu2Mils( aRectangle->GetEnd().y ),
4187  aRectangle->GetUnit(), aRectangle->GetConvert(),
4188  Iu2Mils( aRectangle->GetWidth() ), fill_tab[aRectangle->GetFillMode()] );
4189 }
wxPoint GetEnd() const
Definition: lib_rectangle.h:89
FILL_T GetFillMode() const
Definition: lib_item.h:315
int GetUnit() const
Definition: lib_item.h:309
int GetWidth() const override
Definition: lib_rectangle.h:85
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:312
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxPoint GetPosition() const override
Definition: lib_rectangle.h:76
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References fill_tab, LIB_ITEM::GetConvert(), LIB_RECTANGLE::GetEnd(), LIB_ITEM::GetFillMode(), LIB_RECTANGLE::GetPosition(), LIB_ITEM::GetUnit(), LIB_RECTANGLE::GetWidth(), LIB_RECTANGLE_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ SaveSymbol()

void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol ( LIB_PART aSymbol,
OUTPUTFORMATTER aFormatter,
LIB_PART_MAP aMap = nullptr 
)
static

Definition at line 3766 of file sch_legacy_plugin.cpp.

3768 {
3769  wxCHECK_RET( aSymbol && aSymbol->IsRoot(), "Invalid LIB_PART pointer." );
3770 
3771  // LIB_ALIAS objects are deprecated but we still need to gather up the derived symbols
3772  // and save their names for the old file format.
3773  wxArrayString aliasNames;
3774 
3775  if( aMap )
3776  {
3777  for( auto entry : *aMap )
3778  {
3779  LIB_PART* part = entry.second;
3780 
3781  if( part->IsAlias() && part->GetParent().lock() == aSymbol->SharedPtr() )
3782  aliasNames.Add( part->GetName() );
3783  }
3784  }
3785 
3786  LIB_FIELD& value = aSymbol->GetValueField();
3787 
3788  // First line: it s a comment (component name for readers)
3789  aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3790 
3791  // Save data
3792  aFormatter.Print( 0, "DEF" );
3793  aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
3794 
3795  LIB_FIELD& reference = aSymbol->GetReferenceField();
3796 
3797  if( !reference.GetText().IsEmpty() )
3798  {
3799  aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3800  }
3801  else
3802  {
3803  aFormatter.Print( 0, " ~" );
3804  }
3805 
3806  aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
3807  0, Iu2Mils( aSymbol->GetPinNameOffset() ),
3808  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3809  aSymbol->ShowPinNames() ? 'Y' : 'N',
3810  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3811  aSymbol->IsPower() ? 'P' : 'N' );
3812 
3813  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3814 
3815  if( dateModified != 0 )
3816  {
3817  int sec = dateModified & 63;
3818  int min = ( dateModified >> 6 ) & 63;
3819  int hour = ( dateModified >> 12 ) & 31;
3820  int day = ( dateModified >> 17 ) & 31;
3821  int mon = ( dateModified >> 22 ) & 15;
3822  int year = ( dateModified >> 26 ) + 1990;
3823 
3824  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3825  }
3826 
3827  LIB_FIELDS fields;
3828  aSymbol->GetFields( fields );
3829 
3830  // Mandatory fields:
3831  // may have their own save policy so there is a separate loop for them.
3832  // Empty fields are saved, because the user may have set visibility,
3833  // size and orientation
3834  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3835  {
3836  saveField( &fields[i], aFormatter );
3837  }
3838 
3839  // User defined fields:
3840  // may have their own save policy so there is a separate loop for them.
3841 
3842  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3843 
3844  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3845  {
3846  // There is no need to save empty fields, i.e. no reason to preserve field
3847  // names now that fields names come in dynamically through the template
3848  // fieldnames.
3849  if( !fields[i].GetText().IsEmpty() )
3850  {
3851  fields[i].SetId( fieldId++ );
3852  saveField( &fields[i], aFormatter );
3853  }
3854  }
3855 
3856  // Save the alias list: a line starting by "ALIAS".
3857  if( !aliasNames.IsEmpty() )
3858  {
3859  aFormatter.Print( 0, "ALIAS" );
3860 
3861  for( unsigned i = 0; i < aliasNames.GetCount(); i++ )
3862  {
3863  aFormatter.Print( 0, " %s", TO_UTF8( aliasNames[i] ) );
3864  }
3865 
3866  aFormatter.Print( 0, "\n" );
3867  }
3868 
3869  wxArrayString footprints = aSymbol->GetFootprints();
3870 
3871  // Write the footprint filter list
3872  if( footprints.GetCount() != 0 )
3873  {
3874  aFormatter.Print( 0, "$FPLIST\n" );
3875 
3876  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3877  {
3878  aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3879  }
3880 
3881  aFormatter.Print( 0, "$ENDFPLIST\n" );
3882  }
3883 
3884  // Save graphics items (including pins)
3885  if( !aSymbol->GetDrawItems().empty() )
3886  {
3887  // Sort the draw items in order to editing a file editing by hand.
3888  aSymbol->GetDrawItems().sort();
3889 
3890  aFormatter.Print( 0, "DRAW\n" );
3891 
3892  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3893  {
3894  switch( item.Type() )
3895  {
3896  case LIB_FIELD_T: // Fields have already been saved above.
3897  continue;
3898 
3899  case LIB_ARC_T:
3900  saveArc( (LIB_ARC*) &item, aFormatter );
3901  break;
3902 
3903  case LIB_BEZIER_T:
3904  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3905  break;
3906 
3907  case LIB_CIRCLE_T:
3908  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3909  break;
3910 
3911  case LIB_PIN_T:
3912  savePin( (LIB_PIN* ) &item, aFormatter );
3913  break;
3914 
3915  case LIB_POLYLINE_T:
3916  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3917  break;
3918 
3919  case LIB_RECTANGLE_T:
3920  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3921  break;
3922 
3923  case LIB_TEXT_T:
3924  saveText( ( LIB_TEXT* ) &item, aFormatter );
3925  break;
3926 
3927  default:
3928  ;
3929  }
3930  }
3931 
3932  aFormatter.Print( 0, "ENDDRAW\n" );
3933  }
3934 
3935  aFormatter.Print( 0, "ENDDEF\n" );
3936 }
static void saveCircle(LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter)
int GetPinNameOffset()
wxString GetName() const override
Define a symbol library graphical text item.
Definition: lib_text.h:40
timestamp_t GetDateLastEdition() const
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:237
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Field object used in symbol libraries.
Definition: lib_field.h:59
void sort()
Definition: multivector.h:242
LIB_FIELD & GetValueField()
Return reference to the value field.
static void savePin(LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
static void saveBezier(LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter)
static void saveField(LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
The base class for drawable items used by schematic library components.
Definition: lib_item.h:60
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
bool ShowPinNames()
bool ShowPinNumbers()
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
int GetUnitCount() const override
For items with units, return the number of units.
static void saveText(LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
static void saveRectangle(LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
wxString GetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_shape.cpp:58
PART_SPTR SharedPtr()
PART_REF & GetParent()
static void savePolyLine(LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
Define a library symbol object.
wxArrayString GetFootprints() const
bool IsPower() const
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:223
bool IsAlias() const
static void saveArc(LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter)
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
bool UnitsLocked() const
Check whether part units are interchangeable.
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_PART::GetDateLastEdition(), LIB_PART::GetDrawItems(), LIB_PART::GetFields(), LIB_PART::GetFootprints(), LIB_PART::GetName(), LIB_PART::GetParent(), LIB_PART::GetPinNameOffset(), LIB_PART::GetReferenceField(), GetText(), EDA_TEXT::GetText(), LIB_PART::GetUnitCount(), LIB_PART::GetValueField(), LIB_PART::IsAlias(), LIB_PART::IsPower(), LIB_PART::IsRoot(), LIB_ARC_T, LIB_BEZIER_T, LIB_CIRCLE_T, LIB_FIELD_T, LIB_PIN_T, LIB_POLYLINE_T, LIB_RECTANGLE_T, LIB_TEXT_T, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), saveArc(), saveBezier(), saveCircle(), saveField(), savePin(), savePolyLine(), saveRectangle(), saveText(), LIB_PART::SharedPtr(), LIB_PART::ShowPinNames(), LIB_PART::ShowPinNumbers(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort(), TO_UTF8, and LIB_PART::UnitsLocked().

Referenced by SCH_LEGACY_PLUGIN::FormatPart(), and Save().

◆ saveText()

void SCH_LEGACY_PLUGIN_CACHE::saveText ( LIB_TEXT aText,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4192 of file sch_legacy_plugin.cpp.

4194 {
4195  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
4196 
4197  wxString text = aText->GetText();
4198 
4199  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
4200  {
4201  // convert double quote to similar-looking two apostrophes
4202  text.Replace( wxT( "\"" ), wxT( "''" ) );
4203  text = wxT( "\"" ) + text + wxT( "\"" );
4204  }
4205 
4206  aFormatter.Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
4207  Iu2Mils( aText->GetTextPos().x ), Iu2Mils( aText->GetTextPos().y ),
4208  Iu2Mils( aText->GetTextWidth() ), !aText->IsVisible(),
4209  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
4210 
4211  aFormatter.Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
4212 
4213  char hjustify = 'C';
4214 
4215  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4216  hjustify = 'L';
4217  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4218  hjustify = 'R';
4219 
4220  char vjustify = 'C';
4221 
4222  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4223  vjustify = 'B';
4224  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4225  vjustify = 'T';
4226 
4227  aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
4228 }
bool IsBold() const
Definition: eda_text.h:167
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:184
bool IsVisible() const
Definition: eda_text.h:170
double GetTextAngle() const
Definition: eda_text.h:158
bool IsItalic() const
Definition: eda_text.h:164
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
int GetUnit() const
Definition: lib_item.h:309
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:183
int GetConvert() const
Definition: lib_item.h:312
int GetTextWidth() const
Definition: eda_text.h:226
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212

References LIB_ITEM::GetConvert(), EDA_TEXT::GetHorizJustify(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextWidth(), LIB_ITEM::GetUnit(), EDA_TEXT::GetVertJustify(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsVisible(), LIB_TEXT_T, OUTPUTFORMATTER::Print(), TO_UTF8, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ SetFileName()

void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 554 of file sch_legacy_plugin.cpp.

554 { m_libFileName = aFileName; }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ SetModified()

void SCH_LEGACY_PLUGIN_CACHE::SetModified ( bool  aModified = true)
inline

Member Data Documentation

◆ m_fileModTime

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 479 of file sch_legacy_plugin.cpp.

Referenced by IsFileChanged(), Load(), and Save().

◆ m_fileName

wxString SCH_LEGACY_PLUGIN_CACHE::m_fileName
private

Definition at line 477 of file sch_legacy_plugin.cpp.

Referenced by IsFile().

◆ m_isModified

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 482 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteSymbol(), removeSymbol(), Save(), and SetModified().

◆ m_isWritable

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 481 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

◆ m_libFileName

wxFileName SCH_LEGACY_PLUGIN_CACHE::m_libFileName
private

◆ m_libType

int SCH_LEGACY_PLUGIN_CACHE::m_libType
private

Definition at line 485 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ m_modHash

int SCH_LEGACY_PLUGIN_CACHE::m_modHash = 1
staticprivate

Definition at line 475 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteSymbol(), GetModifyHash(), Load(), and removeSymbol().

◆ m_symbols

◆ m_versionMajor

int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 483 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ m_versionMinor

int SCH_LEGACY_PLUGIN_CACHE::m_versionMinor
private

Definition at line 484 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ SCH_LEGACY_PLUGIN

friend SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN
private

Definition at line 520 of file sch_legacy_plugin.cpp.


The documentation for this class was generated from the following file: