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_TYPE 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 (const LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
 
static void savePin (const LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
 
static void savePolyLine (LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
 
static void saveRectangle (LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
 
static void saveText (const 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
 
SCH_LIB_TYPE 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 476 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 2402 of file sch_legacy_plugin.cpp.

2402  :
2403  m_fileName( aFullPathAndFileName ),
2404  m_libFileName( aFullPathAndFileName ),
2405  m_isWritable( true ),
2406  m_isModified( false )
2407 {
2408  m_versionMajor = -1;
2409  m_versionMinor = -1;
2411 }

References LT_EESCHEMA, m_libType, m_versionMajor, and m_versionMinor.

◆ ~SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE ( )

Definition at line 2414 of file sch_legacy_plugin.cpp.

2415 {
2416  std::vector< LIB_PART* > rootParts;
2417 
2418  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2419  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
2420  delete it->second;
2421 
2422  m_symbols.clear();
2423 }

References m_symbols.

Member Function Documentation

◆ AddSymbol()

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 2544 of file sch_legacy_plugin.cpp.

2545 {
2546  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2547  wxString name = aPart->GetName();
2548  LIB_PART_MAP::iterator it = m_symbols.find( name );
2549 
2550  if( it != m_symbols.end() )
2551  {
2552  removeSymbol( it->second );
2553  }
2554 
2555  m_symbols[ name ] = const_cast< LIB_PART* >( aPart );
2556  m_isModified = true;
2557  ++m_modHash;
2558 }
wxString GetName() const override
const char * name
Definition: DXF_plotter.cpp:59
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 4161 of file sch_legacy_plugin.cpp.

4162 {
4163  LIB_PART_MAP::iterator it = m_symbols.find( aSymbolName );
4164 
4165  if( it == m_symbols.end() )
4166  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
4167  m_libFileName.GetFullName(), aSymbolName ) );
4168 
4169  LIB_PART* part = it->second;
4170 
4171  if( part->IsRoot() )
4172  {
4173  LIB_PART* rootPart = part;
4174 
4175  // Remove the root symbol and all it's children.
4176  m_symbols.erase( it );
4177 
4178  LIB_PART_MAP::iterator it1 = m_symbols.begin();
4179 
4180  while( it1 != m_symbols.end() )
4181  {
4182  if( it1->second->IsAlias() && it1->second->GetParent().lock() == rootPart->SharedPtr() )
4183  {
4184  delete it1->second;
4185  it1 = m_symbols.erase( it1 );
4186  }
4187  else
4188  {
4189  it1++;
4190  }
4191  }
4192 
4193  delete rootPart;
4194  }
4195  else
4196  {
4197  // Just remove the alias.
4198  m_symbols.erase( it );
4199  delete part;
4200  }
4201 
4202  ++m_modHash;
4203  m_isModified = true;
4204 }
PART_SPTR SharedPtr()
Define a library symbol object.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(s)
Definition: 3d_actions.cpp:33
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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 ( void  ) const
inline

Definition at line 559 of file sch_legacy_plugin.cpp.

559 { return m_libFileName.GetFullPath(); }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ GetLibModificationTime()

wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2450 of file sch_legacy_plugin.cpp.

2451 {
2452  wxFileName fn = GetRealFile();
2453 
2454  // update the writable flag while we have a wxFileName, in a network this
2455  // is possibly quite dynamic anyway.
2456  m_isWritable = fn.IsFileWritable();
2457 
2458  return fn.GetModificationTime();
2459 }
wxFileName GetRealFile() const

References GetRealFile(), and m_isWritable.

Referenced by Load().

◆ GetLogicalName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 555 of file sch_legacy_plugin.cpp.

555 { return m_libFileName.GetName(); }

References m_libFileName.

◆ GetModifyHash()

int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline

Definition at line 529 of file sch_legacy_plugin.cpp.

529 { return m_modHash; }

References m_modHash.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

◆ GetRealFile()

wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile ( ) const

Definition at line 2427 of file sch_legacy_plugin.cpp.

2428 {
2429  wxFileName fn( m_libFileName );
2430 
2431 #ifndef __WINDOWS__
2432  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2433  {
2434  char buffer[ PATH_MAX + 1 ];
2435  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2436 
2437  if( pathLen > 0 )
2438  {
2439  buffer[ pathLen ] = '\0';
2440  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2441  fn.Normalize();
2442  }
2443  }
2444 #endif
2445 
2446  return fn;
2447 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96

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 2462 of file sch_legacy_plugin.cpp.

2463 {
2464  return m_fileName == aFullPathAndFileName;
2465 }

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 2468 of file sch_legacy_plugin.cpp.

2469 {
2470  wxFileName fn = GetRealFile();
2471 
2472  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2473  return fn.GetModificationTime() != m_fileModTime;
2474 
2475  return false;
2476 }
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 2561 of file sch_legacy_plugin.cpp.

2562 {
2563  if( !m_libFileName.FileExists() )
2564  {
2565  THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ),
2566  m_libFileName.GetFullPath() ) );
2567  }
2568 
2569  wxCHECK_RET( m_libFileName.IsAbsolute(),
2570  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2571  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2572 
2573  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2574  m_libFileName.GetFullPath() );
2575 
2576  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2577 
2578  if( !reader.ReadLine() )
2579  THROW_IO_ERROR( _( "unexpected end of file" ) );
2580 
2581  const char* line = reader.Line();
2582 
2583  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2584  {
2585  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2586  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2587  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2588  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2589  }
2590 
2591  m_versionMajor = parseInt( reader, line, &line );
2592 
2593  if( *line != '.' )
2594  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2595 
2596  line++;
2597 
2598  m_versionMinor = parseInt( reader, line, &line );
2599 
2600  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2601  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2602 
2603  // Check if this is a symbol library which is the same as a component library but without
2604  // any alias, documentation, footprint filters, etc.
2605  if( strCompare( "SYMBOL", line, &line ) )
2606  {
2607  // Symbol files add date and time stamp info to the header.
2609 
2611  }
2612  else
2613  {
2615  }
2616 
2617  while( reader.ReadLine() )
2618  {
2619  line = reader.Line();
2620 
2621  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2622  continue;
2623 
2624  // Headers where only supported in older library file formats.
2625  if( m_libType == SCH_LIB_TYPE::LT_EESCHEMA && strCompare( "$HEADER", line ) )
2626  loadHeader( reader );
2627 
2628  if( strCompare( "DEF", line ) )
2629  {
2630  // Read one DEF/ENDDEF part entry from library:
2632 
2633  m_symbols[ part->GetName() ] = part;
2634  }
2635  }
2636 
2637  ++m_modHash;
2638 
2639  // Remember the file modification time of library file when the
2640  // cache snapshot was made, so that in a networked environment we will
2641  // reload the cache as needed.
2643 
2645  loadDocs();
2646 }
wxString GetName() const override
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
void loadHeader(FILE_LINE_READER &aReader)
A LINE_READER that reads from an open file.
Definition: richio.h:172
Define a library symbol object.
#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...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static LIB_PART * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_PART_MAP *aMap=nullptr)
#define SCH_PARSE_ERROR(text, reader, pos)
#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...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), GetLibModificationTime(), LIB_PART::GetName(), loadDocs(), loadHeader(), LoadPart(), LT_EESCHEMA, LT_SYMBOL, 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 2945 of file sch_legacy_plugin.cpp.

2948 {
2949  wxString newAliasName;
2950  const char* line = aReader.Line();
2951 
2952  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2953 
2954  wxString utf8Line = wxString::FromUTF8( line );
2955  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2956 
2957  // Parse the ALIAS list.
2958  while( tokens.HasMoreTokens() )
2959  {
2960  newAliasName = tokens.GetNextToken();
2961 
2962  if( aMap )
2963  {
2964  LIB_PART* newPart = new LIB_PART( newAliasName );
2965 
2966  // Inherit the parent mandatory field attributes.
2967  for( int id=0; id<MANDATORY_FIELDS; ++id )
2968  {
2969  LIB_FIELD* field = newPart->GetField( id );
2970 
2971  // the MANDATORY_FIELDS are exactly that in RAM.
2972  wxASSERT( field );
2973 
2974  LIB_FIELD* parentField = aPart->GetField( id );
2975 
2976  wxASSERT( parentField );
2977 
2978  *field = *parentField;
2979 
2980  if( id == VALUE_FIELD )
2981  field->SetText( newAliasName );
2982 
2983  field->SetParent( newPart );
2984  }
2985 
2986  newPart->SetParent( aPart.get() );
2987 
2988  // This will prevent duplicate aliases.
2989  (*aMap)[ newPart->GetName() ] = newPart;
2990  }
2991  }
2992 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
wxString GetName() const override
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
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:164
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
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...
LIB_FIELD * GetField(int aId) const
Return pointer to the requested field.

References LIB_PART::GetField(), LIB_PART::GetName(), LINE_READER::Line(), MANDATORY_FIELDS, LIB_PART::SetParent(), EDA_ITEM::SetParent(), EDA_TEXT::SetText(), strCompare(), and VALUE_FIELD.

Referenced by LoadPart().

◆ loadArc()

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

Definition at line 3222 of file sch_legacy_plugin.cpp.

3224 {
3225  const char* line = aReader.Line();
3226 
3227  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
3228 
3229  LIB_ARC* arc = new LIB_ARC( aPart.get() );
3230 
3231  wxPoint center;
3232 
3233  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3234  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3235 
3236  arc->SetPosition( center );
3237  arc->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
3238 
3239  int angle1 = parseInt( aReader, line, &line );
3240  int angle2 = parseInt( aReader, line, &line );
3241 
3242  NORMALIZE_ANGLE_POS( angle1 );
3243  NORMALIZE_ANGLE_POS( angle2 );
3244  arc->SetFirstRadiusAngle( angle1 );
3245  arc->SetSecondRadiusAngle( angle2 );
3246 
3247  arc->SetUnit( parseInt( aReader, line, &line ) );
3248  arc->SetConvert( parseInt( aReader, line, &line ) );
3249  arc->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3250 
3251  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3252  // when fill mode is no fill (default mode).
3253  if( *line != 0 )
3254  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3255 
3256  // Actual Coordinates of arc ends are read from file
3257  if( *line != 0 )
3258  {
3259  wxPoint arcStart, arcEnd;
3260 
3261  arcStart.x = Mils2Iu( parseInt( aReader, line, &line ) );
3262  arcStart.y = Mils2Iu( parseInt( aReader, line, &line ) );
3263  arcEnd.x = Mils2Iu( parseInt( aReader, line, &line ) );
3264  arcEnd.y = Mils2Iu( parseInt( aReader, line, &line ) );
3265 
3266  arc->SetStart( arcStart );
3267  arc->SetEnd( arcEnd );
3268  }
3269  else
3270  {
3271  // Actual Coordinates of arc ends are not read from file
3272  // (old library), calculate them
3273  wxPoint arcStart( arc->GetRadius(), 0 );
3274  wxPoint arcEnd( arc->GetRadius(), 0 );
3275 
3276  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3277  arcStart += arc->GetPosition();
3278  arc->SetStart( arcStart );
3279  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3280  arcEnd += arc->GetPosition();
3281  arc->SetEnd( arcEnd );
3282  }
3283 
3284  return arc;
3285 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetFillMode(FILL_TYPE aFillMode)
Definition: lib_item.h:301
void SetFirstRadiusAngle(int aAngle)
Definition: lib_arc.h:105
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:288
static FILL_TYPE parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
#define Mils2Iu(x)
void SetWidth(int aWidth) override
Definition: lib_arc.h:100
void SetEnd(const wxPoint &aPoint)
Definition: lib_arc.h:115
#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 SetSecondRadiusAngle(int aAngle)
Definition: lib_arc.h:108
int GetRadius() const
Definition: lib_arc.h:103
void SetConvert(int aConvert)
Definition: lib_item.h:298
void SetUnit(int aUnit)
Definition: lib_item.h:295
void SetRadius(int aRadius)
Definition: lib_arc.h:102
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 SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:249
void SetStart(const wxPoint &aPoint)
Definition: lib_arc.h:112
wxPoint GetPosition() const override
Definition: lib_arc.h:90

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(), and strCompare().

Referenced by loadDrawEntries().

◆ loadBezier()

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

Definition at line 3661 of file sch_legacy_plugin.cpp.

3663 {
3664  const char* line = aReader.Line();
3665 
3666  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3667 
3668  LIB_BEZIER* bezier = new LIB_BEZIER( aPart.get() );
3669 
3670  int points = parseInt( aReader, line, &line );
3671  bezier->SetUnit( parseInt( aReader, line, &line ) );
3672  bezier->SetConvert( parseInt( aReader, line, &line ) );
3673  bezier->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3674 
3675  wxPoint pt;
3676  bezier->Reserve( points );
3677 
3678  for( int i = 0; i < points; i++ )
3679  {
3680  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3681  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3682  bezier->AddPoint( pt );
3683  }
3684 
3685  if( *line != 0 )
3686  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3687 
3688  return bezier;
3689 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetFillMode(FILL_TYPE aFillMode)
Definition: lib_item.h:301
static FILL_TYPE parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
#define Mils2Iu(x)
void Reserve(size_t aCount)
Definition: lib_bezier.h:57
#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 SetConvert(int aConvert)
Definition: lib_item.h:298
void SetUnit(int aUnit)
Definition: lib_item.h:295
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:87
void AddPoint(const wxPoint &aPoint)
Definition: lib_bezier.h:58
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(), and strCompare().

Referenced by loadDrawEntries().

◆ loadCircle()

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

Definition at line 3288 of file sch_legacy_plugin.cpp.

3290 {
3291  const char* line = aReader.Line();
3292 
3293  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3294 
3295  LIB_CIRCLE* circle = new LIB_CIRCLE( aPart.get() );
3296 
3297  wxPoint center;
3298 
3299  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3300  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3301 
3302  circle->SetPosition( center );
3303  circle->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
3304  circle->SetUnit( parseInt( aReader, line, &line ) );
3305  circle->SetConvert( parseInt( aReader, line, &line ) );
3306  circle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3307 
3308  if( *line != 0 )
3309  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3310 
3311  return circle;
3312 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetFillMode(FILL_TYPE aFillMode)
Definition: lib_item.h:301
static FILL_TYPE parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
#define Mils2Iu(x)
#define NULL
void SetRadius(int aRadius)
Definition: lib_circle.h:87
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:298
void SetUnit(int aUnit)
Definition: lib_item.h:295
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:85
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:249

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(), and strCompare().

Referenced by loadDrawEntries().

◆ loadDocs()

void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2649 of file sch_legacy_plugin.cpp.

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

References _, DATASHEET_FIELD, DOC_EXT, DOCFILE_IDENT, LIB_ID::FixIllegalChars(), Format(), FROM_UTF8(), LIB_PART::GetField(), m_libFileName, m_symbols, NULL, FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_PART::SetDescription(), 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 3143 of file sch_legacy_plugin.cpp.

3147 {
3148  const char* line = aReader.Line();
3149 
3150  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
3151 
3152  line = aReader.ReadLine();
3153 
3154  while( line )
3155  {
3156  if( strCompare( "ENDDRAW", line, &line ) )
3157  return;
3158 
3159  switch( line[0] )
3160  {
3161  case 'A': // Arc
3162  aPart->AddDrawItem( loadArc( aPart, aReader ) );
3163  break;
3164 
3165  case 'C': // Circle
3166  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
3167  break;
3168 
3169  case 'T': // Text
3170  aPart->AddDrawItem( loadText( aPart, aReader, aMajorVersion, aMinorVersion ) );
3171  break;
3172 
3173  case 'S': // Square
3174  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
3175  break;
3176 
3177  case 'X': // Pin Description
3178  aPart->AddDrawItem( loadPin( aPart, aReader ) );
3179  break;
3180 
3181  case 'P': // Polyline
3182  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
3183  break;
3184 
3185  case 'B': // Bezier Curves
3186  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
3187  break;
3188 
3189  case '#': // Comment
3190  case '\n': // Empty line
3191  case '\r':
3192  case 0:
3193  break;
3194 
3195  default:
3196  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3197  }
3198 
3199  line = aReader.ReadLine();
3200  }
3201 
3202  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
3203 }
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
Return a pointer to the last line that was read in.
Definition: richio.h:117
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
Read 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 2995 of file sch_legacy_plugin.cpp.

2997 {
2998  const char* line = aReader.Line();
2999 
3000  wxCHECK_RET( *line == 'F', "Invalid field line" );
3001 
3002  wxString text;
3003  int id;
3004 
3005  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
3006  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
3007 
3008  LIB_FIELD* field;
3009 
3010  if( id >= 0 && id < MANDATORY_FIELDS )
3011  {
3012  field = aPart->GetField( id );
3013 
3014  // this will fire only if somebody broke a constructor or editor.
3015  // MANDATORY_FIELDS are always present in ram resident components, no
3016  // exceptions, and they always have their names set, even fixed fields.
3017  wxASSERT( field );
3018  }
3019  else
3020  {
3021  field = new LIB_FIELD( aPart.get(), id );
3022  aPart->AddDrawItem( field );
3023  }
3024 
3025  // Skip to the first double quote.
3026  while( *line != '"' && *line != 0 )
3027  line++;
3028 
3029  if( *line == 0 )
3030  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
3031 
3032  parseQuotedString( text, aReader, line, &line, true );
3033 
3034  field->SetText( text );
3035 
3036  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
3037  // not save like this.
3038  if( text.size() == 1 && text[0] == '~' )
3039  field->SetText( wxEmptyString );
3040  else
3041  field->SetText( text );
3042 
3043  wxPoint pos;
3044 
3045  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3046  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3047  field->SetPosition( pos );
3048 
3049  wxSize textSize;
3050 
3051  textSize.x = textSize.y = Mils2Iu( parseInt( aReader, line, &line ) );
3052  field->SetTextSize( textSize );
3053 
3054  char textOrient = parseChar( aReader, line, &line );
3055 
3056  if( textOrient == 'H' )
3057  field->SetTextAngle( TEXT_ANGLE_HORIZ );
3058  else if( textOrient == 'V' )
3059  field->SetTextAngle( TEXT_ANGLE_VERT );
3060  else
3061  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
3062 
3063  char textVisible = parseChar( aReader, line, &line );
3064 
3065  if( textVisible == 'V' )
3066  field->SetVisible( true );
3067  else if ( textVisible == 'I' )
3068  field->SetVisible( false );
3069  else
3070  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
3071 
3072  // It may be technically correct to use the library version to determine if the field text
3073  // attributes are present. If anyone knows if that is valid and what version that would be,
3074  // please change this to test the library version rather than an EOL or the quoted string
3075  // of the field name.
3076  if( *line != 0 && *line != '"' )
3077  {
3078  char textHJustify = parseChar( aReader, line, &line );
3079 
3080  if( textHJustify == 'C' )
3082  else if( textHJustify == 'L' )
3084  else if( textHJustify == 'R' )
3086  else
3087  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
3088 
3089  wxString attributes;
3090 
3091  parseUnquotedString( attributes, aReader, line, &line );
3092 
3093  size_t attrSize = attributes.size();
3094 
3095  if( !(attrSize == 3 || attrSize == 1 ) )
3096  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
3097 
3098  switch( (wxChar) attributes[0] )
3099  {
3100  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3101  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3102  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3103  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
3104  }
3105 
3106  if( attrSize == 3 )
3107  {
3108  wxChar attr_1 = attributes[1];
3109  wxChar attr_2 = attributes[2];
3110 
3111  if( attr_1 == 'I' ) // Italic
3112  field->SetItalic( true );
3113  else if( attr_1 != 'N' ) // No italics is default, check for error.
3114  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
3115 
3116  if ( attr_2 == 'B' ) // Bold
3117  field->SetBold( true );
3118  else if( attr_2 != 'N' ) // No bold is default, check for error.
3119  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
3120  }
3121  }
3122 
3123  // Fields in RAM must always have names.
3124  if( id >= 0 && id < MANDATORY_FIELDS )
3125  {
3126  // Fields in RAM must always have names, because we are trying to get
3127  // less dependent on field ids and more dependent on names.
3128  // Plus assumptions are made in the field editors.
3130 
3131  // Ensure the VALUE field = the part name (can be not the case
3132  // with malformed libraries: edited by hand, or converted from other tools)
3133  if( id == VALUE_FIELD )
3134  field->SetText( aPart->GetName() );
3135  }
3136  else
3137  {
3138  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
3139  }
3140 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetItalic(bool isItalic)
Definition: eda_text.h:186
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:192
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.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:244
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)
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
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 const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
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:208
#define _(s)
Definition: 3d_actions.cpp:33
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:249
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:174
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:189

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, and VALUE_FIELD.

Referenced by LoadPart().

◆ loadFootprintFilters()

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

Definition at line 3692 of file sch_legacy_plugin.cpp.

3694 {
3695  const char* line = aReader.Line();
3696 
3697  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3698 
3699  line = aReader.ReadLine();
3700 
3701  wxArrayString footprintFilters;
3702 
3703  while( line )
3704  {
3705  if( strCompare( "$ENDFPLIST", line, &line ) )
3706  {
3707  aPart->SetFPFilters( footprintFilters );
3708  return;
3709  }
3710 
3711  wxString footprint;
3712 
3713  parseUnquotedString( footprint, aReader, line, &line );
3714  footprintFilters.Add( footprint );
3715  line = aReader.ReadLine();
3716  }
3717 
3718  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3719 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
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
Read 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 2750 of file sch_legacy_plugin.cpp.

2751 {
2752  const char* line = aReader.Line();
2753 
2754  wxASSERT( strCompare( "$HEADER", line, &line ) );
2755 
2756  while( aReader.ReadLine() )
2757  {
2758  line = (char*) aReader;
2759 
2760  // The time stamp saved in old library files is not used or saved in the latest
2761  // library file version.
2762  if( strCompare( "TimeStamp", line, &line ) )
2763  continue;
2764  else if( strCompare( "$ENDHEADER", line, &line ) )
2765  return;
2766  }
2767 
2768  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2769 }
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:198
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
#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 2772 of file sch_legacy_plugin.cpp.

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

3442 {
3443  const char* line = aReader.Line();
3444 
3445  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3446 
3447  wxString name;
3448  wxString number;
3449 
3450  size_t pos = 2; // "X" plus ' ' space character.
3451  wxString tmp;
3452  wxString utf8Line = wxString::FromUTF8( line );
3453  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3454 
3455  if( tokens.CountTokens() < 11 )
3456  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3457 
3458  tmp = tokens.GetNextToken();
3459  name = tmp;
3460  pos += tmp.size() + 1;
3461 
3462  tmp = tokens.GetNextToken();
3463  number = tmp ;
3464  pos += tmp.size() + 1;
3465 
3466  long num;
3467  wxPoint position;
3468 
3469  tmp = tokens.GetNextToken();
3470 
3471  if( !tmp.ToLong( &num ) )
3472  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3473  aReader.LineNumber(), pos );
3474 
3475  pos += tmp.size() + 1;
3476  position.x = Mils2Iu( (int) num );
3477 
3478  tmp = tokens.GetNextToken();
3479 
3480  if( !tmp.ToLong( &num ) )
3481  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3482  aReader.LineNumber(), pos );
3483 
3484  pos += tmp.size() + 1;
3485  position.y = Mils2Iu( (int) num );
3486 
3487  tmp = tokens.GetNextToken();
3488 
3489  if( !tmp.ToLong( &num ) )
3490  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3491  aReader.LineNumber(), pos );
3492 
3493  pos += tmp.size() + 1;
3494  int length = Mils2Iu( (int) num );
3495 
3496 
3497  tmp = tokens.GetNextToken();
3498 
3499  if( tmp.size() > 1 )
3500  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3501  aReader.LineNumber(), pos );
3502 
3503  pos += tmp.size() + 1;
3504  int orientation = tmp[0];
3505 
3506  tmp = tokens.GetNextToken();
3507 
3508  if( !tmp.ToLong( &num ) )
3509  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3510  aReader.LineNumber(), pos );
3511 
3512  pos += tmp.size() + 1;
3513  int numberTextSize = Mils2Iu( (int) num );
3514 
3515  tmp = tokens.GetNextToken();
3516 
3517  if( !tmp.ToLong( &num ) )
3518  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3519  aReader.LineNumber(), pos );
3520 
3521  pos += tmp.size() + 1;
3522  int nameTextSize = Mils2Iu( (int) num );
3523 
3524  tmp = tokens.GetNextToken();
3525 
3526  if( !tmp.ToLong( &num ) )
3527  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3528  aReader.LineNumber(), pos );
3529 
3530  pos += tmp.size() + 1;
3531  int unit = (int) num;
3532 
3533  tmp = tokens.GetNextToken();
3534 
3535  if( !tmp.ToLong( &num ) )
3536  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3537  aReader.LineNumber(), pos );
3538 
3539  pos += tmp.size() + 1;
3540  int convert = (int) num;
3541 
3542  tmp = tokens.GetNextToken();
3543 
3544  if( tmp.size() != 1 )
3545  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3546  aReader.LineNumber(), pos );
3547 
3548  pos += tmp.size() + 1;
3549  char type = tmp[0];
3550  ELECTRICAL_PINTYPE pinType;
3551 
3552  switch( type )
3553  {
3554  case 'I': pinType = ELECTRICAL_PINTYPE::PT_INPUT; break;
3555  case 'O': pinType = ELECTRICAL_PINTYPE::PT_OUTPUT; break;
3556  case 'B': pinType = ELECTRICAL_PINTYPE::PT_BIDI; break;
3557  case 'T': pinType = ELECTRICAL_PINTYPE::PT_TRISTATE; break;
3558  case 'P': pinType = ELECTRICAL_PINTYPE::PT_PASSIVE; break;
3559  case 'U': pinType = ELECTRICAL_PINTYPE::PT_UNSPECIFIED; break;
3560  case 'W': pinType = ELECTRICAL_PINTYPE::PT_POWER_IN; break;
3561  case 'w': pinType = ELECTRICAL_PINTYPE::PT_POWER_OUT; break;
3562  case 'C': pinType = ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR; break;
3563  case 'E': pinType = ELECTRICAL_PINTYPE::PT_OPENEMITTER; break;
3564  case 'N': pinType = ELECTRICAL_PINTYPE::PT_NC; break;
3565  default:
3566  THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(), aReader.Line(),
3567  aReader.LineNumber(), pos );
3568  }
3569 
3570 
3571  LIB_PIN* pin = new LIB_PIN( aPart.get(), name, number, orientation, pinType, length,
3572  nameTextSize, numberTextSize, convert, position, unit );
3573 
3574  // Optional
3575  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3576  {
3577  tmp = tokens.GetNextToken();
3578 
3579  enum
3580  {
3581  INVERTED = 1 << 0,
3582  CLOCK = 1 << 1,
3583  LOWLEVEL_IN = 1 << 2,
3584  LOWLEVEL_OUT = 1 << 3,
3585  FALLING_EDGE = 1 << 4,
3586  NONLOGIC = 1 << 5
3587  };
3588 
3589  int flags = 0;
3590 
3591  for( int j = tmp.size(); j > 0; )
3592  {
3593  switch( tmp[--j].GetValue() )
3594  {
3595  case '~': break;
3596  case 'N': pin->SetVisible( false ); break;
3597  case 'I': flags |= INVERTED; break;
3598  case 'C': flags |= CLOCK; break;
3599  case 'L': flags |= LOWLEVEL_IN; break;
3600  case 'V': flags |= LOWLEVEL_OUT; break;
3601  case 'F': flags |= FALLING_EDGE; break;
3602  case 'X': flags |= NONLOGIC; break;
3603  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3604  aReader.Line(), aReader.LineNumber(), pos );
3605  }
3606 
3607  pos += 1;
3608  }
3609 
3610  switch( flags )
3611  {
3612  case 0: pin->SetShape( GRAPHIC_PINSHAPE::LINE ); break;
3613  case INVERTED: pin->SetShape( GRAPHIC_PINSHAPE::INVERTED ); break;
3614  case CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::CLOCK ); break;
3616  case LOWLEVEL_IN: pin->SetShape( GRAPHIC_PINSHAPE::INPUT_LOW ); break;
3617  case LOWLEVEL_IN | CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::CLOCK_LOW ); break;
3618  case LOWLEVEL_OUT: pin->SetShape( GRAPHIC_PINSHAPE::OUTPUT_LOW ); break;
3619  case FALLING_EDGE: pin->SetShape( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK ); break;
3620  case NONLOGIC: pin->SetShape( GRAPHIC_PINSHAPE::NONLOGIC ); break;
3621  default:
3622  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3623  }
3624  }
3625 
3626  return pin;
3627 }
power input (GND, VCC for ICs). Must be connected to a power output.
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:109
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:129
pin for passive components: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
std::chrono::steady_clock CLOCK
#define Mils2Iu(x)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
#define NULL
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
void SetVisible(bool aVisible)
Definition: lib_pin.h:148
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:59
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:34
usual pin input: must be connected
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...
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(), Mils2Iu, name, NONLOGIC, NULL, OUTPUT_LOW, 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, LIB_PIN::SetShape(), LIB_PIN::SetVisible(), strCompare(), and THROW_PARSE_ERROR.

Referenced by loadDrawEntries().

◆ loadPolyLine()

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

Definition at line 3630 of file sch_legacy_plugin.cpp.

3632 {
3633  const char* line = aReader.Line();
3634 
3635  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3636 
3637  LIB_POLYLINE* polyLine = new LIB_POLYLINE( aPart.get() );
3638 
3639  int points = parseInt( aReader, line, &line );
3640  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3641  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3642  polyLine->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3643  polyLine->Reserve( points );
3644 
3645  wxPoint pt;
3646 
3647  for( int i = 0; i < points; i++ )
3648  {
3649  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3650  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3651  polyLine->AddPoint( pt );
3652  }
3653 
3654  if( *line != 0 )
3655  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3656 
3657  return polyLine;
3658 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetFillMode(FILL_TYPE aFillMode)
Definition: lib_item.h:301
static FILL_TYPE parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetWidth(int aWidth) override
Definition: lib_polyline.h:103
#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 SetConvert(int aConvert)
Definition: lib_item.h:298
void SetUnit(int aUnit)
Definition: lib_item.h:295
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(), and strCompare().

Referenced by loadDrawEntries().

◆ loadRectangle()

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

Definition at line 3408 of file sch_legacy_plugin.cpp.

3410 {
3411  const char* line = aReader.Line();
3412 
3413  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3414 
3415  LIB_RECTANGLE* rectangle = new LIB_RECTANGLE( aPart.get() );
3416 
3417  wxPoint pos;
3418 
3419  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3420  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3421  rectangle->SetPosition( pos );
3422 
3423  wxPoint end;
3424 
3425  end.x = Mils2Iu( parseInt( aReader, line, &line ) );
3426  end.y = Mils2Iu( parseInt( aReader, line, &line ) );
3427  rectangle->SetEnd( end );
3428 
3429  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3430  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3431  rectangle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3432 
3433  if( *line != 0 )
3434  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3435 
3436  return rectangle;
3437 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetFillMode(FILL_TYPE aFillMode)
Definition: lib_item.h:301
static FILL_TYPE parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
#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 SetConvert(int aConvert)
Definition: lib_item.h:298
void SetUnit(int aUnit)
Definition: lib_item.h:295
void SetEnd(const wxPoint &aEnd)
Definition: lib_rectangle.h:88
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 SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:249

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(), and strCompare().

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 3315 of file sch_legacy_plugin.cpp.

3319 {
3320  const char* line = aReader.Line();
3321 
3322  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3323 
3324  LIB_TEXT* text = new LIB_TEXT( aPart.get() );
3325 
3326  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3327 
3328  wxPoint center;
3329 
3330  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3331  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3332  text->SetPosition( center );
3333 
3334  wxSize size;
3335 
3336  size.x = size.y = Mils2Iu( parseInt( aReader, line, &line ) );
3337  text->SetTextSize( size );
3338  text->SetVisible( !parseInt( aReader, line, &line ) );
3339  text->SetUnit( parseInt( aReader, line, &line ) );
3340  text->SetConvert( parseInt( aReader, line, &line ) );
3341 
3342  wxString str;
3343 
3344  // If quoted string loading fails, load as not quoted string.
3345  if( *line == '"' )
3346  parseQuotedString( str, aReader, line, &line );
3347  else
3348  {
3349  parseUnquotedString( str, aReader, line, &line );
3350 
3351  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3352  str.Replace( "~", " " );
3353  }
3354 
3355  if( !str.IsEmpty() )
3356  {
3357  // convert two apostrophes back to double quote
3358  str.Replace( "''", "\"" );
3359  }
3360 
3361  text->SetText( str );
3362 
3363  // Here things are murky and not well defined. At some point it appears the format
3364  // was changed to add text properties. However rather than add the token to the end of
3365  // the text definition, it was added after the string and no mention if the file
3366  // verion was bumped or not so this code make break on very old component libraries.
3367  //
3368  // Update: apparently even in the latest version this can be different so added a test
3369  // for end of line before checking for the text properties.
3370  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
3371  && LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3372  {
3373  if( strCompare( "Italic", line, &line ) )
3374  text->SetItalic( true );
3375  else if( !strCompare( "Normal", line, &line ) )
3376  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3377 
3378  if( parseInt( aReader, line, &line ) > 0 )
3379  text->SetBold( true );
3380 
3381  // Some old libaries version > 2.0 do not have these options for text justification:
3382  if( !is_eol( *line ) )
3383  {
3384  switch( parseChar( aReader, line, &line ) )
3385  {
3386  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3387  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3388  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3389  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3390  aReader, line );
3391  }
3392 
3393  switch( parseChar( aReader, line, &line ) )
3394  {
3395  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3396  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3397  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3398  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3399  aReader, line );
3400  }
3401  }
3402  }
3403 
3404  return text;
3405 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
Define a symbol library graphical text item.
Definition: lib_text.h:40
void SetItalic(bool isItalic)
Definition: eda_text.h:186
void SetVisible(bool aVisible)
Definition: eda_text.h:192
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:244
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:121
#define NULL
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:209
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:298
void SetUnit(int aUnit)
Definition: lib_item.h:295
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:208
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 SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:249
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:174
void SetBold(bool aBold)
Definition: eda_text.h:189

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(), and strCompare().

Referenced by loadDrawEntries().

◆ parseFillMode()

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

Definition at line 3206 of file sch_legacy_plugin.cpp.

3208 {
3209  switch ( parseChar( aReader, aLine, aOutput ) )
3210  {
3211  case 'F': return FILL_TYPE::FILLED_SHAPE;
3212  case 'f': return FILL_TYPE::FILLED_WITH_BG_BODYCOLOR;
3213  case 'N': return FILL_TYPE::NO_FILL;
3214  default: SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3215  }
3216 
3217  // This will never be reached but quiets the compiler warnings
3218  return FILL_TYPE::NO_FILL;
3219 }
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 2479 of file sch_legacy_plugin.cpp.

2480 {
2481  wxCHECK_MSG( aPart != NULL, NULL, "NULL pointer cannot be removed from library." );
2482 
2483  LIB_PART* firstChild = NULL;
2484  LIB_PART_MAP::iterator it = m_symbols.find( aPart->GetName() );
2485 
2486  if( it == m_symbols.end() )
2487  return NULL;
2488 
2489  // If the entry pointer doesn't match the name it is mapped to in the library, we
2490  // have done something terribly wrong.
2491  wxCHECK_MSG( *it->second == aPart, NULL,
2492  "Pointer mismatch while attempting to remove alias entry <" + aPart->GetName() +
2493  "> from library cache <" + m_libFileName.GetName() + ">." );
2494 
2495  // If the symbol is a root symbol used by other symbols find the first alias that uses
2496  // the root part and make it the new root.
2497  if( aPart->IsRoot() )
2498  {
2499  for( auto entry : m_symbols )
2500  {
2501  if( entry.second->IsAlias()
2502  && entry.second->GetParent().lock() == aPart->SharedPtr() )
2503  {
2504  firstChild = entry.second;
2505  break;
2506  }
2507  }
2508 
2509  if( firstChild )
2510  {
2511  for( LIB_ITEM& drawItem : aPart->GetDrawItems() )
2512  {
2513  if( drawItem.Type() == LIB_FIELD_T )
2514  {
2515  LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
2516 
2517  if( firstChild->FindField( field.GetCanonicalName() ) )
2518  continue;
2519  }
2520 
2521  LIB_ITEM* newItem = (LIB_ITEM*) drawItem.Clone();
2522  drawItem.SetParent( firstChild );
2523  firstChild->AddDrawItem( newItem );
2524  }
2525 
2526  // Reparent the remaining aliases.
2527  for( auto entry : m_symbols )
2528  {
2529  if( entry.second->IsAlias()
2530  && entry.second->GetParent().lock() == aPart->SharedPtr() )
2531  entry.second->SetParent( firstChild );
2532  }
2533  }
2534  }
2535 
2536  m_symbols.erase( it );
2537  delete aPart;
2538  m_isModified = true;
2539  ++m_modHash;
2540  return firstChild;
2541 }
Field object used in symbol libraries.
Definition: lib_field.h:59
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:164
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:97
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
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
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:374
Define a library symbol object.

References LIB_PART::AddDrawItem(), EDA_ITEM::Clone(), LIB_PART::FindField(), LIB_FIELD::GetCanonicalName(), LIB_PART::GetDrawItems(), LIB_PART::GetName(), LIB_PART::IsRoot(), LIB_FIELD_T, m_isModified, m_libFileName, m_modHash, m_symbols, 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 3722 of file sch_legacy_plugin.cpp.

3723 {
3724  if( !m_isModified )
3725  return;
3726 
3727  // Write through symlinks, don't replace them
3728  wxFileName fn = GetRealFile();
3729 
3730  auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
3731  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3732  formatter->Print( 0, "#encoding utf-8\n");
3733 
3734  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); it++ )
3735  {
3736  if( !it->second->IsRoot() )
3737  continue;
3738 
3739  SaveSymbol( it->second, *formatter.get(), &m_symbols );
3740  }
3741 
3742  formatter->Print( 0, "#\n#End Library\n" );
3743  formatter.reset();
3744 
3745  m_fileModTime = fn.GetModificationTime();
3746  m_isModified = false;
3747 
3748  if( aSaveDocFile )
3749  saveDocFile();
3750 }
#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)
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 3896 of file sch_legacy_plugin.cpp.

3897 {
3898  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3899 
3900  int x1 = aArc->GetFirstRadiusAngle();
3901 
3902  if( x1 > 1800 )
3903  x1 -= 3600;
3904 
3905  int x2 = aArc->GetSecondRadiusAngle();
3906 
3907  if( x2 > 1800 )
3908  x2 -= 3600;
3909 
3910  aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3911  Iu2Mils( aArc->GetPosition().x ), Iu2Mils( aArc->GetPosition().y ),
3912  Iu2Mils( aArc->GetRadius() ), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3913  Iu2Mils( aArc->GetWidth() ), fill_tab[ static_cast<int>( aArc->GetFillMode() ) ],
3914  Iu2Mils( aArc->GetStart().x ), Iu2Mils( aArc->GetStart().y ),
3915  Iu2Mils( aArc->GetEnd().x ), Iu2Mils( aArc->GetEnd().y ) );
3916 }
int GetSecondRadiusAngle() const
Definition: lib_arc.h:109
FILL_TYPE GetFillMode() const
Definition: lib_item.h:302
int GetUnit() const
Definition: lib_item.h:296
wxPoint GetStart() const
Definition: lib_arc.h:111
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:299
int GetRadius() const
Definition: lib_arc.h:103
int GetWidth() const override
Definition: lib_arc.h:99
wxPoint GetEnd() const
Definition: lib_arc.h:114
int GetFirstRadiusAngle() const
Definition: lib_arc.h:106
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161
wxPoint GetPosition() const override
Definition: lib_arc.h:90

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(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveBezier()

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

Definition at line 3919 of file sch_legacy_plugin.cpp.

3921 {
3922  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3923 
3924  aFormatter.Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3925  aBezier->GetUnit(), aBezier->GetConvert(), Iu2Mils( aBezier->GetWidth() ) );
3926 
3927  for( const auto& pt : aBezier->GetPoints() )
3928  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
3929 
3930  aFormatter.Print( 0, " %c\n", fill_tab[static_cast<int>( aBezier->GetFillMode() )] );
3931 }
int GetWidth() const override
Definition: lib_bezier.h:86
FILL_TYPE GetFillMode() const
Definition: lib_item.h:302
int GetUnit() const
Definition: lib_item.h:296
const int fill_tab[3]
Definition: lib_item.cpp:32
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:68
int GetConvert() const
Definition: lib_item.h:299
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

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 3934 of file sch_legacy_plugin.cpp.

3936 {
3937  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3938 
3939  aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n",
3940  Iu2Mils( aCircle->GetPosition().x ), Iu2Mils( aCircle->GetPosition().y ),
3941  Iu2Mils( aCircle->GetRadius() ), aCircle->GetUnit(), aCircle->GetConvert(),
3942  Iu2Mils( aCircle->GetWidth() ), fill_tab[static_cast<int>( aCircle->GetFillMode() )] );
3943 }
wxPoint GetPosition() const override
Definition: lib_circle.h:72
int GetWidth() const override
Definition: lib_circle.h:84
FILL_TYPE GetFillMode() const
Definition: lib_item.h:302
int GetUnit() const
Definition: lib_item.h:296
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetRadius() const
Definition: lib_circle.h:88
int GetConvert() const
Definition: lib_item.h:299
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

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(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveDocFile()

void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 4125 of file sch_legacy_plugin.cpp.

4126 {
4127  wxFileName fileName = m_libFileName;
4128 
4129  fileName.SetExt( DOC_EXT );
4130  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
4131 
4132  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
4133 
4134  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
4135  {
4136  wxString description = it->second->GetDescription();
4137  wxString keyWords = it->second->GetKeyWords();
4138  wxString docFileName = it->second->GetDatasheetField().GetText();
4139 
4140  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
4141  continue;
4142 
4143  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
4144 
4145  if( !description.IsEmpty() )
4146  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
4147 
4148  if( !keyWords.IsEmpty() )
4149  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
4150 
4151  if( !docFileName.IsEmpty() )
4152  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
4153 
4154  formatter.Print( 0, "$ENDCMP\n" );
4155  }
4156 
4157  formatter.Print( 0, "#\n#End Doc Library\n" );
4158 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:49
Used for text file output.
Definition: richio.h:453
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408

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

Referenced by Save().

◆ saveField()

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

Definition at line 3946 of file sch_legacy_plugin.cpp.

3947 {
3948  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3949 
3950  int hjustify, vjustify;
3951  int id = aField->GetId();
3952  wxString text = aField->GetText();
3953 
3954  hjustify = 'C';
3955 
3956  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3957  hjustify = 'L';
3958  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3959  hjustify = 'R';
3960 
3961  vjustify = 'C';
3962 
3963  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3964  vjustify = 'B';
3965  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3966  vjustify = 'T';
3967 
3968  aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3969  id,
3970  EscapedUTF8( text ).c_str(), // wraps in quotes
3971  Iu2Mils( aField->GetTextPos().x ), Iu2Mils( aField->GetTextPos().y ),
3972  Iu2Mils( aField->GetTextWidth() ),
3973  aField->GetTextAngle() == 0 ? 'H' : 'V',
3974  aField->IsVisible() ? 'V' : 'I',
3975  hjustify, vjustify,
3976  aField->IsItalic() ? 'I' : 'N',
3977  aField->IsBold() ? 'B' : 'N' );
3978 
3979  /* Save field name, if necessary
3980  * Field name is saved only if it is not the default name.
3981  * Just because default name depends on the language and can change from
3982  * a country to another
3983  */
3984  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3985 
3986  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3987  aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3988 
3989  aFormatter.Print( 0, "\n" );
3990 }
bool IsBold() const
Definition: eda_text.h:190
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:206
bool IsVisible() const
Definition: eda_text.h:193
double GetTextAngle() const
Definition: eda_text.h:181
int GetId() const
Definition: lib_field.h:138
std::string EscapedUTF8(wxString aString)
Return an 8 bit UTF8 string given aString in Unicode form.
Definition: string.cpp:309
bool IsItalic() const
Definition: eda_text.h:187
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
int GetTextWidth() const
Definition: eda_text.h:248
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
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:133
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

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(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ savePin()

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

Definition at line 3993 of file sch_legacy_plugin.cpp.

3994 {
3995  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3996 
3997  int Etype;
3998 
3999  switch( aPin->GetType() )
4000  {
4001  default:
4002  case ELECTRICAL_PINTYPE::PT_INPUT: Etype = 'I'; break;
4003  case ELECTRICAL_PINTYPE::PT_OUTPUT: Etype = 'O'; break;
4004  case ELECTRICAL_PINTYPE::PT_BIDI: Etype = 'B'; break;
4005  case ELECTRICAL_PINTYPE::PT_TRISTATE: Etype = 'T'; break;
4006  case ELECTRICAL_PINTYPE::PT_PASSIVE: Etype = 'P'; break;
4007  case ELECTRICAL_PINTYPE::PT_UNSPECIFIED: Etype = 'U'; break;
4008  case ELECTRICAL_PINTYPE::PT_POWER_IN: Etype = 'W'; break;
4009  case ELECTRICAL_PINTYPE::PT_POWER_OUT: Etype = 'w'; break;
4010  case ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR: Etype = 'C'; break;
4011  case ELECTRICAL_PINTYPE::PT_OPENEMITTER: Etype = 'E'; break;
4012  case ELECTRICAL_PINTYPE::PT_NC: Etype = 'N'; break;
4013  }
4014 
4015  if( !aPin->GetName().IsEmpty() )
4016  aFormatter.Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
4017  else
4018  aFormatter.Print( 0, "X ~" );
4019 
4020  aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
4021  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
4022  Iu2Mils( aPin->GetPosition().x ), Iu2Mils( aPin->GetPosition().y ),
4023  Iu2Mils( (int) aPin->GetLength() ), (int) aPin->GetOrientation(),
4024  Iu2Mils( aPin->GetNumberTextSize() ), Iu2Mils( aPin->GetNameTextSize() ),
4025  aPin->GetUnit(), aPin->GetConvert(), Etype );
4026 
4027  if( aPin->GetShape() != GRAPHIC_PINSHAPE::LINE || !aPin->IsVisible() )
4028  aFormatter.Print( 0, " " );
4029 
4030  if( !aPin->IsVisible() )
4031  aFormatter.Print( 0, "N" );
4032 
4033  switch( aPin->GetShape() )
4034  {
4035  case GRAPHIC_PINSHAPE::LINE: break;
4036  case GRAPHIC_PINSHAPE::INVERTED: aFormatter.Print( 0, "I" ); break;
4037  case GRAPHIC_PINSHAPE::CLOCK: aFormatter.Print( 0, "C" ); break;
4038  case GRAPHIC_PINSHAPE::INVERTED_CLOCK: aFormatter.Print( 0, "IC" ); break;
4039  case GRAPHIC_PINSHAPE::INPUT_LOW: aFormatter.Print( 0, "L" ); break;
4040  case GRAPHIC_PINSHAPE::CLOCK_LOW: aFormatter.Print( 0, "CL" ); break;
4041  case GRAPHIC_PINSHAPE::OUTPUT_LOW: aFormatter.Print( 0, "V" ); break;
4042  case GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK: aFormatter.Print( 0, "F" ); break;
4043  case GRAPHIC_PINSHAPE::NONLOGIC: aFormatter.Print( 0, "X" ); break;
4044  default: wxFAIL_MSG( "Invalid pin shape" );
4045  }
4046 
4047  aFormatter.Print( 0, "\n" );
4048 
4049  const_cast<LIB_PIN*>( aPin )->ClearFlags( IS_CHANGED );
4050 }
power input (GND, VCC for ICs). Must be connected to a power output.
#define IS_CHANGED
Item was edited, and modified.
Definition: eda_item.h:102
int GetOrientation() const
Definition: lib_pin.h:125
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:128
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)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
int GetUnit() const
Definition: lib_item.h:296
const wxString & GetName() const
Definition: lib_pin.h:156
bool IsVisible() const
Definition: lib_pin.h:147
int GetNameTextSize() const
Definition: lib_pin.h:174
int GetConvert() const
Definition: lib_item.h:299
wxPoint GetPosition() const override
Definition: lib_pin.h:258
const wxString & GetNumber() const
Definition: lib_pin.h:165
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:134
int GetNumberTextSize() const
Definition: lib_pin.h:177
int GetLength() const
Definition: lib_pin.h:131
usual pin input: must be connected
input or output (like port for a microprocessor)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
not connected (must be left open)
output of a regulator: intended to be connected to power input pins
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

References 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, and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ savePolyLine()

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

Definition at line 4053 of file sch_legacy_plugin.cpp.

4055 {
4056  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
4057 
4058  int ccount = aPolyLine->GetCornerCount();
4059 
4060  aFormatter.Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
4061  Iu2Mils( aPolyLine->GetWidth() ) );
4062 
4063  for( const auto& pt : aPolyLine->GetPolyPoints() )
4064  {
4065  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
4066  }
4067 
4068  aFormatter.Print( 0, " %c\n", fill_tab[static_cast<int>( aPolyLine->GetFillMode() )] );
4069 }
int GetWidth() const override
Definition: lib_polyline.h:102
unsigned GetCornerCount() const
Definition: lib_polyline.h:73
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:60
FILL_TYPE GetFillMode() const
Definition: lib_item.h:302
int GetUnit() const
Definition: lib_item.h:296
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:299
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

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 4072 of file sch_legacy_plugin.cpp.

4074 {
4075  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
4076  "Invalid LIB_RECTANGLE object." );
4077 
4078  aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n",
4079  Iu2Mils( aRectangle->GetPosition().x ),
4080  Iu2Mils( aRectangle->GetPosition().y ),
4081  Iu2Mils( aRectangle->GetEnd().x ), Iu2Mils( aRectangle->GetEnd().y ),
4082  aRectangle->GetUnit(), aRectangle->GetConvert(),
4083  Iu2Mils( aRectangle->GetWidth() ), fill_tab[static_cast<int>( aRectangle->GetFillMode() )] );
4084 }
wxPoint GetEnd() const
Definition: lib_rectangle.h:89
FILL_TYPE GetFillMode() const
Definition: lib_item.h:302
int GetUnit() const
Definition: lib_item.h:296
int GetWidth() const override
Definition: lib_rectangle.h:85
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:299
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
wxPoint GetPosition() const override
Definition: lib_rectangle.h:76
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

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(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ SaveSymbol()

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

Definition at line 3753 of file sch_legacy_plugin.cpp.

3755 {
3756  wxCHECK_RET( aSymbol && aSymbol->IsRoot(), "Invalid LIB_PART pointer." );
3757 
3758  // LIB_ALIAS objects are deprecated but we still need to gather up the derived symbols
3759  // and save their names for the old file format.
3760  wxArrayString aliasNames;
3761 
3762  if( aMap )
3763  {
3764  for( auto entry : *aMap )
3765  {
3766  LIB_PART* part = entry.second;
3767 
3768  if( part->IsAlias() && part->GetParent().lock() == aSymbol->SharedPtr() )
3769  aliasNames.Add( part->GetName() );
3770  }
3771  }
3772 
3773  LIB_FIELD& value = aSymbol->GetValueField();
3774 
3775  // First line: it s a comment (component name for readers)
3776  aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3777 
3778  // Save data
3779  aFormatter.Print( 0, "DEF" );
3780  aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
3781 
3782  LIB_FIELD& reference = aSymbol->GetReferenceField();
3783 
3784  if( !reference.GetText().IsEmpty() )
3785  {
3786  aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3787  }
3788  else
3789  {
3790  aFormatter.Print( 0, " ~" );
3791  }
3792 
3793  aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
3794  0, Iu2Mils( aSymbol->GetPinNameOffset() ),
3795  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3796  aSymbol->ShowPinNames() ? 'Y' : 'N',
3797  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3798  aSymbol->IsPower() ? 'P' : 'N' );
3799 
3800  timestamp_t dateModified = aSymbol->GetLastModDate();
3801 
3802  if( dateModified != 0 )
3803  {
3804  int sec = dateModified & 63;
3805  int min = ( dateModified >> 6 ) & 63;
3806  int hour = ( dateModified >> 12 ) & 31;
3807  int day = ( dateModified >> 17 ) & 31;
3808  int mon = ( dateModified >> 22 ) & 15;
3809  int year = ( dateModified >> 26 ) + 1990;
3810 
3811  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3812  }
3813 
3814  std::vector<LIB_FIELD*> fields;
3815  aSymbol->GetFields( fields );
3816 
3817  // Mandatory fields:
3818  // may have their own save policy so there is a separate loop for them.
3819  // Empty fields are saved, because the user may have set visibility,
3820  // size and orientation
3821  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3822  saveField( fields[i], aFormatter );
3823 
3824  // User defined fields:
3825  // may have their own save policy so there is a separate loop for them.
3826 
3827  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3828 
3829  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3830  {
3831  // There is no need to save empty fields, i.e. no reason to preserve field
3832  // names now that fields names come in dynamically through the template
3833  // fieldnames.
3834  if( !fields[i]->GetText().IsEmpty() )
3835  {
3836  fields[i]->SetId( fieldId++ );
3837  saveField( fields[i], aFormatter );
3838  }
3839  }
3840 
3841  // Save the alias list: a line starting by "ALIAS".
3842  if( !aliasNames.IsEmpty() )
3843  {
3844  aFormatter.Print( 0, "ALIAS" );
3845 
3846  for( unsigned i = 0; i < aliasNames.GetCount(); i++ )
3847  aFormatter.Print( 0, " %s", TO_UTF8( aliasNames[i] ) );
3848 
3849  aFormatter.Print( 0, "\n" );
3850  }
3851 
3852  wxArrayString footprints = aSymbol->GetFPFilters();
3853 
3854  // Write the footprint filter list
3855  if( footprints.GetCount() != 0 )
3856  {
3857  aFormatter.Print( 0, "$FPLIST\n" );
3858 
3859  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3860  aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3861 
3862  aFormatter.Print( 0, "$ENDFPLIST\n" );
3863  }
3864 
3865  // Save graphics items (including pins)
3866  if( !aSymbol->GetDrawItems().empty() )
3867  {
3868  // Sort the draw items in order to editing a file editing by hand.
3869  aSymbol->GetDrawItems().sort();
3870 
3871  aFormatter.Print( 0, "DRAW\n" );
3872 
3873  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3874  {
3875  switch( item.Type() )
3876  {
3877  default:
3878  case LIB_FIELD_T: /* Fields have already been saved above. */ break;
3879  case LIB_ARC_T: saveArc( (LIB_ARC*) &item, aFormatter ); break;
3880  case LIB_BEZIER_T: saveBezier( (LIB_BEZIER*) &item, aFormatter ); break;
3881  case LIB_CIRCLE_T: saveCircle( ( LIB_CIRCLE* ) &item, aFormatter ); break;
3882  case LIB_PIN_T: savePin( (LIB_PIN* ) &item, aFormatter ); break;
3883  case LIB_POLYLINE_T: savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter ); break;
3884  case LIB_RECTANGLE_T: saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter ); break;
3885  case LIB_TEXT_T: saveText( ( LIB_TEXT* ) &item, aFormatter ); break;
3886  }
3887  }
3888 
3889  aFormatter.Print( 0, "ENDDRAW\n" );
3890  }
3891 
3892  aFormatter.Print( 0, "ENDDEF\n" );
3893 }
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
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:243
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:248
LIB_FIELD & GetValueField()
Return reference to the value field.
wxArrayString GetFPFilters() const
static void saveBezier(LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter)
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
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 saveRectangle(LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
PART_SPTR SharedPtr()
PART_REF & GetParent()
static void savePolyLine(LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
Define a library symbol object.
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this part.
static void saveText(const LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: kiid.h:32
static void savePin(const LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
static void saveField(const LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
bool IsPower() const
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.
timestamp_t GetLastModDate() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
bool UnitsLocked() const
Check whether part units are interchangeable.
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_PART::GetDrawItems(), LIB_PART::GetFields(), LIB_PART::GetFPFilters(), LIB_PART::GetLastModDate(), LIB_PART::GetName(), LIB_PART::GetParent(), LIB_PART::GetPinNameOffset(), LIB_PART::GetReferenceField(), 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 ( const LIB_TEXT aText,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4087 of file sch_legacy_plugin.cpp.

4088 {
4089  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
4090 
4091  wxString text = aText->GetText();
4092 
4093  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
4094  {
4095  // convert double quote to similar-looking two apostrophes
4096  text.Replace( wxT( "\"" ), wxT( "''" ) );
4097  text = wxT( "\"" ) + text + wxT( "\"" );
4098  }
4099 
4100  aFormatter.Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
4101  Iu2Mils( aText->GetTextPos().x ), Iu2Mils( aText->GetTextPos().y ),
4102  Iu2Mils( aText->GetTextWidth() ), !aText->IsVisible(),
4103  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
4104 
4105  aFormatter.Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
4106 
4107  char hjustify = 'C';
4108 
4109  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4110  hjustify = 'L';
4111  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4112  hjustify = 'R';
4113 
4114  char vjustify = 'C';
4115 
4116  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4117  vjustify = 'B';
4118  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4119  vjustify = 'T';
4120 
4121  aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
4122 }
bool IsBold() const
Definition: eda_text.h:190
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:206
bool IsVisible() const
Definition: eda_text.h:193
double GetTextAngle() const
Definition: eda_text.h:181
bool IsItalic() const
Definition: eda_text.h:187
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
int GetUnit() const
Definition: lib_item.h:296
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
int GetConvert() const
Definition: lib_item.h:299
int GetTextWidth() const
Definition: eda_text.h:248
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

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, and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ SetFileName()

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

Definition at line 557 of file sch_legacy_plugin.cpp.

557 { 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 482 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 480 of file sch_legacy_plugin.cpp.

Referenced by IsFile().

◆ m_isModified

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 485 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 484 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

◆ m_libFileName

wxFileName SCH_LEGACY_PLUGIN_CACHE::m_libFileName
private

◆ m_libType

SCH_LIB_TYPE SCH_LEGACY_PLUGIN_CACHE::m_libType
private

Definition at line 488 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 478 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 486 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 487 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 523 of file sch_legacy_plugin.cpp.


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