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 DeleteAlias (const wxString &aAliasName)
 
void DeleteSymbol (const wxString &aAliasName)
 
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
 

Private Member Functions

LIB_PARTloadPart (FILE_LINE_READER &aReader)
 
void loadHeader (FILE_LINE_READER &aReader)
 
void loadAliases (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadField (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadDrawEntries (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadFootprintFilters (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadDocs ()
 
LIB_ARCloadArc (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_CIRCLEloadCircle (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_TEXTloadText (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_RECTANGLEloadRectangle (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_PINloadPin (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_POLYLINEloadPolyLine (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_BEZIERloadBezier (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
FILL_T parseFillMode (FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
 
bool checkForDuplicates (wxString &aAliasName)
 
LIB_ALIASremoveAlias (LIB_ALIAS *aAlias)
 
void saveDocFile ()
 
void saveSymbol (LIB_PART *aSymbol, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveArc (LIB_ARC *aArc, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveBezier (LIB_BEZIER *aBezier, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveCircle (LIB_CIRCLE *aCircle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveField (LIB_FIELD *aField, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void savePin (LIB_PIN *aPin, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void savePolyLine (LIB_POLYLINE *aPolyLine, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveRectangle (LIB_RECTANGLE *aRectangle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveText (LIB_TEXT *aText, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 

Private Attributes

wxString m_fileName
 
wxFileName m_libFileName
 
wxDateTime m_fileModTime
 
LIB_ALIAS_MAP m_aliases
 
bool m_isWritable
 
bool m_isModified
 
int m_versionMajor
 
int m_versionMinor
 
int m_libType
 
friend SCH_LEGACY_PLUGIN
 

Static Private Attributes

static int m_modHash = 1
 

Detailed Description

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

not placed into a header.

Definition at line 464 of file sch_legacy_plugin.cpp.

Constructor & Destructor Documentation

SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE ( const wxString &  aLibraryPath)
SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE ( )

Definition at line 2186 of file sch_legacy_plugin.cpp.

References LIB_PART::GetAliasCount(), GetChars(), GetLogicalName(), m_aliases, and traceSchLegacyPlugin.

2187 {
2188  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2189  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2190  {
2191  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2192  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2193  LIB_PART* part = it->second->GetPart();
2194  LIB_ALIAS* alias = it->second;
2195  delete alias;
2196 
2197  // When the last alias of a part is destroyed, the part is no longer required and it
2198  // too is destroyed.
2199  if( part && part->GetAliasCount() == 0 )
2200  delete part;
2201  }
2202 
2203  m_aliases.clear();
2204 }
Part library alias object definition.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
size_t GetAliasCount() const
Define a library symbol object.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
wxString GetLogicalName() const

Member Function Documentation

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 2275 of file sch_legacy_plugin.cpp.

References LIB_PART::GetAliasNames(), LIB_PART::GetName(), i, m_aliases, m_isModified, m_modHash, and removeAlias().

Referenced by GetModifyHash().

2276 {
2277  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2278  wxArrayString aliasNames = aPart->GetAliasNames();
2279 
2280  for( size_t i = 0; i < aliasNames.size(); i++ )
2281  {
2282  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2283 
2284  if( it != m_aliases.end() )
2285  removeAlias( it->second );
2286 
2287  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2288 
2289  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2290  aPart->GetName() +">." );
2291 
2292  m_aliases[ aliasNames[i] ] = alias;
2293  }
2294 
2295  m_isModified = true;
2296  ++m_modHash;
2297 }
Part library alias object definition.
Define a library symbol object.
LIB_ALIAS * removeAlias(LIB_ALIAS *aAlias)
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
const wxString & GetName() const
bool SCH_LEGACY_PLUGIN_CACHE::checkForDuplicates ( wxString &  aAliasName)
private

Definition at line 2672 of file sch_legacy_plugin.cpp.

References m_aliases.

Referenced by loadAliases().

2673 {
2674  wxCHECK_MSG( !aAliasName.IsEmpty(), false, "alias name cannot be empty" );
2675 
2676  // The alias name is not a duplicate so don't change it.
2677  if( m_aliases.find( aAliasName ) == m_aliases.end() )
2678  return false;
2679 
2680  int dupCounter = 1;
2681  wxString newAlias = aAliasName;
2682 
2683  // If the alias is already loaded, the library is broken. It may have been possible in
2684  // the past that this could happen so we assign a new alias name to prevent any conflicts
2685  // rather than throw an exception.
2686  while( m_aliases.find( newAlias ) != m_aliases.end() )
2687  {
2688  newAlias = aAliasName << dupCounter;
2689  dupCounter++;
2690  }
2691 
2692  aAliasName = newAlias;
2693 
2694  return true;
2695 }
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

Definition at line 3991 of file sch_legacy_plugin.cpp.

References Format(), LIB_ALIAS::GetPart(), m_aliases, m_isModified, m_libFileName, m_modHash, next(), LIB_PART::RemoveAlias(), and THROW_IO_ERROR.

Referenced by DeleteSymbol(), and GetModifyHash().

3992 {
3993  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3994 
3995  if( it == m_aliases.end() )
3996  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3997  m_libFileName.GetFullName(), aAliasName ) );
3998 
3999  LIB_ALIAS* alias = it->second;
4000  LIB_PART* part = alias->GetPart();
4001 
4002  alias = part->RemoveAlias( alias );
4003 
4004  if( !alias )
4005  {
4006  delete part;
4007 
4008  if( m_aliases.size() > 1 )
4009  {
4010  LIB_ALIAS_MAP::iterator next = it;
4011  next++;
4012 
4013  if( next == m_aliases.end() )
4014  next = m_aliases.begin();
4015 
4016  alias = next->second;
4017  }
4018  }
4019 
4020  m_aliases.erase( it );
4021  ++m_modHash;
4022  m_isModified = true;
4023 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol object.
LIB_PART * GetPart() const
Get the shared LIB_PART.
void RemoveAlias(const wxString &aName)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aAliasName)

Definition at line 4026 of file sch_legacy_plugin.cpp.

References DeleteAlias(), Format(), LIB_PART::GetAliasNames(), LIB_ALIAS::GetPart(), i, m_aliases, m_libFileName, and THROW_IO_ERROR.

Referenced by GetModifyHash().

4027 {
4028  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4029 
4030  if( it == m_aliases.end() )
4031  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4032  m_libFileName.GetFullName(), aAliasName ) );
4033 
4034  LIB_ALIAS* alias = it->second;
4035  LIB_PART* part = alias->GetPart();
4036 
4037  wxArrayString aliasNames = part->GetAliasNames();
4038 
4039  // Deleting all of the aliases deletes the symbol from the library.
4040  for( size_t i = 0; i < aliasNames.Count(); i++ )
4041  DeleteAlias( aliasNames[i] );
4042 }
Part library alias object definition.
void DeleteAlias(const wxString &aAliasName)
Define a library symbol object.
LIB_PART * GetPart() const
Get the shared LIB_PART.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 553 of file sch_legacy_plugin.cpp.

553 { return m_libFileName.GetFullPath(); }
wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2207 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by GetModifyHash(), and Load().

2208 {
2209  // update the writable flag while we have a wxFileName, in a network this
2210  // is possibly quite dynamic anyway.
2211  m_isWritable = m_libFileName.IsFileWritable();
2212 
2213  return m_libFileName.GetModificationTime();
2214 }
wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 549 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

549 { return m_libFileName.GetName(); }
int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline
bool SCH_LEGACY_PLUGIN_CACHE::IsFile ( const wxString &  aFullPathAndFileName) const

Definition at line 2217 of file sch_legacy_plugin.cpp.

References m_fileName.

Referenced by GetModifyHash().

2218 {
2219  return m_fileName == aFullPathAndFileName;
2220 }
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2223 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by GetModifyHash().

2224 {
2225  if( m_fileModTime.IsValid() && m_libFileName.IsOk() && m_libFileName.FileExists() )
2226  return m_libFileName.GetModificationTime() != m_fileModTime;
2227 
2228  return false;
2229 }
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 2300 of file sch_legacy_plugin.cpp.

References Format(), GetLibModificationTime(), LIBRARY_TYPE_EESCHEMA, LIBRARY_TYPE_SYMBOL, loadDocs(), loadHeader(), loadPart(), m_fileModTime, m_libFileName, m_libType, m_modHash, m_versionMajor, m_versionMinor, parseInt(), SCH_PARSE_ERROR, strCompare(), THROW_IO_ERROR, traceSchLegacyPlugin, and USE_OLD_DOC_FILE_FORMAT.

Referenced by GetModifyHash().

2301 {
2302  wxCHECK_RET( m_libFileName.IsAbsolute(),
2303  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2304  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2305 
2306  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2307  m_libFileName.GetFullPath() );
2308 
2309  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2310 
2311  if( !reader.ReadLine() )
2312  THROW_IO_ERROR( _( "unexpected end of file" ) );
2313 
2314  const char* line = reader.Line();
2315 
2316  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2317  {
2318  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2319  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2320  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2321  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2322  }
2323 
2324  m_versionMajor = parseInt( reader, line, &line );
2325 
2326  if( *line != '.' )
2327  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2328 
2329  line++;
2330 
2331  m_versionMinor = parseInt( reader, line, &line );
2332 
2333  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2334  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2335 
2336  // Check if this is a symbol library which is the same as a component library but without
2337  // any alias, documentation, footprint filters, etc.
2338  if( strCompare( "SYMBOL", line, &line ) )
2339  {
2340  // Symbol files add date and time stamp info to the header.
2342 
2344  }
2345  else
2346  {
2348  }
2349 
2350  while( reader.ReadLine() )
2351  {
2352  line = reader.Line();
2353 
2354  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2355  continue;
2356 
2357  // Headers where only supported in older library file formats.
2358  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2359  loadHeader( reader );
2360 
2361  if( strCompare( "DEF", line ) )
2362  {
2363  // Read one DEF/ENDDEF part entry from library:
2364  loadPart( reader );
2365  }
2366  }
2367 
2368  ++m_modHash;
2369 
2370  // Remember the file modification time of library file when the
2371  // cache snapshot was made, so that in a networked environment we will
2372  // reload the cache as needed.
2374 
2376  loadDocs();
2377 }
static int parseInt(FILE_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...
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
void loadHeader(FILE_LINE_READER &aReader)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
Definition: class_library.h:75
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
LIB_PART * loadPart(FILE_LINE_READER &aReader)
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
void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2698 of file sch_legacy_plugin.cpp.

References checkForDuplicates(), LINE_READER::Line(), parseUnquotedString(), and strCompare().

Referenced by loadPart().

2700 {
2701  wxString newAlias;
2702  const char* line = aReader.Line();
2703 
2704  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2705 
2706  // Parse the ALIAS list.
2707  wxString alias;
2708  parseUnquotedString( alias, aReader, line, &line );
2709 
2710  while( !alias.IsEmpty() )
2711  {
2712  newAlias = alias;
2713  checkForDuplicates( newAlias );
2714  aPart->AddAlias( newAlias );
2715  alias.clear();
2716  parseUnquotedString( alias, aReader, line, &line, true );
2717  }
2718 }
static void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
bool checkForDuplicates(wxString &aAliasName)
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_ARC * SCH_LEGACY_PLUGIN_CACHE::loadArc ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2955 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), NORMALIZE_ANGLE_POS(), parseFillMode(), parseInt(), RotatePoint(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

2957 {
2958  const char* line = aReader.Line();
2959 
2960  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
2961 
2962  std::unique_ptr< LIB_ARC > arc( new LIB_ARC( aPart.get() ) );
2963 
2964  wxPoint center;
2965 
2966  center.x = parseInt( aReader, line, &line );
2967  center.y = parseInt( aReader, line, &line );
2968 
2969  arc->SetPosition( center );
2970  arc->SetRadius( parseInt( aReader, line, &line ) );
2971 
2972  int angle1 = parseInt( aReader, line, &line );
2973  int angle2 = parseInt( aReader, line, &line );
2974 
2975  NORMALIZE_ANGLE_POS( angle1 );
2976  NORMALIZE_ANGLE_POS( angle2 );
2977  arc->SetFirstRadiusAngle( angle1 );
2978  arc->SetSecondRadiusAngle( angle2 );
2979 
2980  arc->SetUnit( parseInt( aReader, line, &line ) );
2981  arc->SetConvert( parseInt( aReader, line, &line ) );
2982  arc->SetWidth( parseInt( aReader, line, &line ) );
2983 
2984  // Old libraries (version <= 2.2) do not have always this FILL MODE param
2985  // when fill mode is no fill (default mode).
2986  if( *line != 0 )
2987  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
2988 
2989  // Actual Coordinates of arc ends are read from file
2990  if( *line != 0 )
2991  {
2992  wxPoint arcStart, arcEnd;
2993 
2994  arcStart.x = parseInt( aReader, line, &line );
2995  arcStart.y = parseInt( aReader, line, &line );
2996  arcEnd.x = parseInt( aReader, line, &line );
2997  arcEnd.y = parseInt( aReader, line, &line );
2998 
2999  arc->SetStart( arcStart );
3000  arc->SetEnd( arcEnd );
3001  }
3002  else
3003  {
3004  // Actual Coordinates of arc ends are not read from file
3005  // (old library), calculate them
3006  wxPoint arcStart( arc->GetRadius(), 0 );
3007  wxPoint arcEnd( arc->GetRadius(), 0 );
3008 
3009  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3010  arcStart += arc->GetPosition();
3011  arc->SetStart( arcStart );
3012  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3013  arcEnd += arc->GetPosition();
3014  arc->SetEnd( arcEnd );
3015  }
3016 
3017  return arc.release();
3018 }
static int parseInt(FILE_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 RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:241
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_BEZIER * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3412 of file sch_legacy_plugin.cpp.

References bezier(), i, LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3414 {
3415  const char* line = aReader.Line();
3416 
3417  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3418 
3419  std::unique_ptr< LIB_BEZIER > bezier( new LIB_BEZIER( aPart.get() ) );
3420 
3421  int points = parseInt( aReader, line, &line );
3422  bezier->SetUnit( parseInt( aReader, line, &line ) );
3423  bezier->SetConvert( parseInt( aReader, line, &line ) );
3424  bezier->SetWidth( parseInt( aReader, line, &line ) );
3425 
3426  wxPoint pt;
3427 
3428  for( int i = 0; i < points; i++ )
3429  {
3430  pt.x = parseInt( aReader, line, &line );
3431  pt.y = parseInt( aReader, line, &line );
3432  bezier->AddPoint( pt );
3433  }
3434 
3435  if( *line != 0 )
3436  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3437 
3438  return bezier.release();
3439 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static dpoint_t bezier(double t, dpoint_t p0, dpoint_t p1, dpoint_t p2, dpoint_t p3)
Definition: trace.cpp:260
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
size_t i
Definition: json11.cpp:597
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...
Class LIB_BEZIER defines bezier curve graphic body item.
Definition: lib_bezier.h:39
LIB_CIRCLE * SCH_LEGACY_PLUGIN_CACHE::loadCircle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3021 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3023 {
3024  const char* line = aReader.Line();
3025 
3026  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3027 
3028  std::unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
3029 
3030  wxPoint center;
3031 
3032  center.x = parseInt( aReader, line, &line );
3033  center.y = parseInt( aReader, line, &line );
3034 
3035  circle->SetPosition( center );
3036  circle->SetRadius( parseInt( aReader, line, &line ) );
3037  circle->SetUnit( parseInt( aReader, line, &line ) );
3038  circle->SetConvert( parseInt( aReader, line, &line ) );
3039  circle->SetWidth( parseInt( aReader, line, &line ) );
3040 
3041  if( *line != 0 )
3042  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3043 
3044  return circle.release();
3045 }
static int parseInt(FILE_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...
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2380 of file sch_legacy_plugin.cpp.

References DOC_EXT, DOCFILE_IDENT, Format(), FROM_UTF8(), m_aliases, m_libFileName, parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_ALIAS::SetDescription(), LIB_ALIAS::SetDocFileName(), LIB_ALIAS::SetKeyWords(), strCompare(), THROW_IO_ERROR, and LIB_ALIAS::ValidateName().

Referenced by Load().

2381 {
2382  const char* line;
2383  wxString text;
2384  wxString aliasName;
2385  wxFileName fn = m_libFileName;
2386  LIB_ALIAS* alias = NULL;;
2387 
2388  fn.SetExt( DOC_EXT );
2389 
2390  // Not all libraries will have a document file.
2391  if( !fn.FileExists() )
2392  return;
2393 
2394  if( !fn.IsFileReadable() )
2395  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2396  "document file \"%s\"" ), fn.GetFullPath() ) );
2397 
2398  FILE_LINE_READER reader( fn.GetFullPath() );
2399 
2400  line = reader.ReadLine();
2401 
2402  if( !line )
2403  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2404 
2405  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2406  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2407  reader, line );
2408 
2409  while( reader.ReadLine() )
2410  {
2411  line = reader.Line();
2412 
2413  if( *line == '#' ) // Comment line.
2414  continue;
2415 
2416  if( !strCompare( "$CMP", line, &line ) != 0 )
2417  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2418 
2419  parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
2420  LIB_ALIAS::ValidateName( aliasName );
2421  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2422 
2423  if( it == m_aliases.end() )
2424  wxLogWarning( "Alias '%s' not found in library:\n\n"
2425  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2426  reader.LineNumber(), (int) (line - reader.Line() ) );
2427  else
2428  alias = it->second;
2429 
2430  // Read the curent alias associated doc.
2431  // if the alias does not exist, just skip the description
2432  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2433  while( reader.ReadLine() )
2434  {
2435  line = reader.Line();
2436 
2437  if( !line )
2438  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2439 
2440  if( strCompare( "$ENDCMP", line, &line ) )
2441  break;
2442 
2443  text = FROM_UTF8( line + 2 );
2444  text = text.Trim();
2445 
2446  switch( line[0] )
2447  {
2448  case 'D':
2449  if( alias )
2450  alias->SetDescription( text );
2451  break;
2452 
2453  case 'K':
2454  if( alias )
2455  alias->SetKeyWords( text );
2456  break;
2457 
2458  case 'F':
2459  if( alias )
2460  alias->SetDocFileName( text );
2461  break;
2462 
2463  case '#':
2464  break;
2465 
2466  default:
2467  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2468  }
2469  }
2470  }
2471 }
Part library alias object definition.
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
static void ValidateName(wxString &aName)
Helper function to replace illegal chars in symbol names
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void SetDocFileName(const wxString &aDocFileName)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define DOCFILE_IDENT
static void parseUnquotedString(wxString &aString, FILE_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 DOC_EXT
Definition: class_library.h:50
void SetDescription(const wxString &aDescription)
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
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...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2867 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2869 {
2870  const char* line = aReader.Line();
2871 
2872  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
2873 
2874  line = aReader.ReadLine();
2875 
2876  while( line )
2877  {
2878  if( strCompare( "ENDDRAW", line, &line ) )
2879  return;
2880 
2881  switch( line[0] )
2882  {
2883  case 'A': // Arc
2884  aPart->AddDrawItem( loadArc( aPart, aReader ) );
2885  break;
2886 
2887  case 'C': // Circle
2888  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
2889  break;
2890 
2891  case 'T': // Text
2892  aPart->AddDrawItem( loadText( aPart, aReader ) );
2893  break;
2894 
2895  case 'S': // Square
2896  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
2897  break;
2898 
2899  case 'X': // Pin Description
2900  aPart->AddDrawItem( loadPin( aPart, aReader ) );
2901  break;
2902 
2903  case 'P': // Polyline
2904  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
2905  break;
2906 
2907  case 'B': // Bezier Curves
2908  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
2909  break;
2910 
2911  case '#': // Comment
2912  case '\n': // Empty line
2913  case '\r':
2914  case 0:
2915  break;
2916 
2917  default:
2918  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
2919  }
2920 
2921  line = aReader.ReadLine();
2922  }
2923 
2924  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
2925 }
LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
LIB_BEZIER * loadBezier(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_CIRCLE * loadCircle(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_ARC * loadArc(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
LIB_TEXT * loadText(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_POLYLINE * loadPolyLine(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
#define SCH_PARSE_ERROR(text, reader, pos)
LIB_RECTANGLE * loadRectangle(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
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 SCH_LEGACY_PLUGIN_CACHE::loadField ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2721 of file sch_legacy_plugin.cpp.

References TEMPLATE_FIELDNAME::GetDefaultFieldName(), LIB_FIELD::GetId(), 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(), EDA_TEXT::m_Text, MANDATORY_FIELDS, name, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, VALUE, wxPoint::x, and wxPoint::y.

Referenced by loadPart().

2723 {
2724  const char* line = aReader.Line();
2725 
2726  wxCHECK_RET( *line == 'F', "Invalid field line" );
2727 
2728  int id;
2729 
2730  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2731  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2732 
2733  std::unique_ptr< LIB_FIELD > field( new LIB_FIELD( aPart.get(), id ) );
2734 
2735  // Skip to the first double quote.
2736  while( *line != '"' && *line != 0 )
2737  line++;
2738 
2739  if( *line == 0 )
2740  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2741 
2742  wxString text;
2743  parseQuotedString( text, aReader, line, &line, true );
2744 
2745  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2746  // not save like this.
2747  if( text.size() == 1 && text[0] == '~' )
2748  text.clear();
2749 
2750  field->m_Text = text;
2751 
2752  wxPoint pos;
2753 
2754  pos.x = parseInt( aReader, line, &line );
2755  pos.y = parseInt( aReader, line, &line );
2756  field->SetPosition( pos );
2757 
2758  wxSize textSize;
2759 
2760  textSize.x = textSize.y = parseInt( aReader, line, &line );
2761  field->SetTextSize( textSize );
2762 
2763  char textOrient = parseChar( aReader, line, &line );
2764 
2765  if( textOrient == 'H' )
2766  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2767  else if( textOrient == 'V' )
2768  field->SetTextAngle( TEXT_ANGLE_VERT );
2769  else
2770  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
2771 
2772  char textVisible = parseChar( aReader, line, &line );
2773 
2774  if( textVisible == 'V' )
2775  field->SetVisible( true );
2776  else if ( textVisible == 'I' )
2777  field->SetVisible( false );
2778  else
2779  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
2780 
2781  // It may be technically correct to use the library version to determine if the field text
2782  // attributes are present. If anyone knows if that is valid and what version that would be,
2783  // please change this to test the library version rather than an EOL or the quoted string
2784  // of the field name.
2785  if( *line != 0 && *line != '"' )
2786  {
2787  char textHJustify = parseChar( aReader, line, &line );
2788 
2789  if( textHJustify == 'C' )
2790  field->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2791  else if( textHJustify == 'L' )
2792  field->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2793  else if( textHJustify == 'R' )
2794  field->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2795  else
2796  SCH_PARSE_ERROR( "invalid field text horizontal justification parameter",
2797  aReader, line );
2798 
2799  wxString attributes;
2800 
2801  parseUnquotedString( attributes, aReader, line, &line );
2802 
2803  if( !(attributes.size() == 3 || attributes.size() == 1 ) )
2804  SCH_PARSE_ERROR( "invalid field text attributes size",
2805  aReader, line );
2806 
2807  if( attributes[0] == 'C' )
2808  field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2809  else if( attributes[0] == 'B' )
2810  field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2811  else if( attributes[0] == 'T' )
2812  field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2813  else
2814  SCH_PARSE_ERROR( "invalid field text vertical justification parameter",
2815  aReader, line );
2816 
2817  if( attributes.size() == 3 )
2818  {
2819  if( attributes[1] == 'I' ) // Italic
2820  field->SetItalic( true );
2821  else if( attributes[1] != 'N' ) // No italics is default, check for error.
2822  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
2823 
2824  if ( attributes[2] == 'B' ) // Bold
2825  field->SetBold( true );
2826  else if( attributes[2] != 'N' ) // No bold is default, check for error.
2827  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
2828  }
2829  }
2830 
2831  // Fields in RAM must always have names.
2832  if( (unsigned) id < MANDATORY_FIELDS )
2833  {
2834  // Fields in RAM must always have names, because we are trying to get
2835  // less dependent on field ids and more dependent on names.
2836  // Plus assumptions are made in the field editors.
2837  field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
2838 
2839  LIB_FIELD* fixedField = aPart->GetField( field->GetId() );
2840 
2841  // this will fire only if somebody broke a constructor or editor.
2842  // MANDATORY_FIELDS are always present in ram resident components, no
2843  // exceptions, and they always have their names set, even fixed fields.
2844  wxASSERT( fixedField );
2845 
2846  *fixedField = *field;
2847 
2848  // Ensure the VALUE field = the part name (can be not the case
2849  // with malformed libraries: edited by hand, or converted from other tools)
2850  if( fixedField->GetId() == VALUE )
2851  fixedField->m_Text = aPart->GetName();
2852  }
2853  else
2854  {
2855  wxString name;
2856 
2857  parseQuotedString( name, aReader, line, &line, true ); // Optional.
2858 
2859  if( !name.IsEmpty() )
2860  field->m_name = name;
2861 
2862  aPart->AddDrawItem( field.release() ); // LIB_FIELD* is now owned by the LIB_PART.
2863  }
2864 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
wxString m_Text
Definition: eda_text.h:344
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static char parseChar(FILE_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.
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
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
#define TEXT_ANGLE_VERT
Definition: common.h:92
int GetId() const
Definition: lib_field.h:138
static void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:61
static void parseQuotedString(wxString &aString, FILE_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 VALUE
void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3442 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

3444 {
3445  const char* line = aReader.Line();
3446 
3447  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3448 
3449  line = aReader.ReadLine();
3450 
3451  while( line )
3452  {
3453  if( strCompare( "$ENDFPLIST", line, &line ) )
3454  return;
3455 
3456  wxString footprint;
3457 
3458  parseUnquotedString( footprint, aReader, line, &line );
3459  aPart->GetFootprints().Add( footprint );
3460  line = aReader.ReadLine();
3461  }
3462 
3463  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3464 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
static void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SCH_LEGACY_PLUGIN_CACHE::loadHeader ( FILE_LINE_READER aReader)
private

Definition at line 2474 of file sch_legacy_plugin.cpp.

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

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

2475 {
2476  const char* line = aReader.Line();
2477 
2478  wxASSERT( strCompare( "$HEADER", line, &line ) );
2479 
2480  while( aReader.ReadLine() )
2481  {
2482  line = (char*) aReader;
2483 
2484  // The time stamp saved in old library files is not used or saved in the latest
2485  // library file version.
2486  if( strCompare( "TimeStamp", line, &line ) )
2487  continue;
2488  else if( strCompare( "$ENDHEADER", line, &line ) )
2489  return;
2490  }
2491 
2492  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2493 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_PART * SCH_LEGACY_PLUGIN_CACHE::loadPart ( FILE_LINE_READER aReader)
private

Definition at line 2496 of file sch_legacy_plugin.cpp.

References EDA_TEXT::Empty(), Format(), LIB_ALIAS::GetName(), LIB_ALIAS::IsRoot(), LIB_VERSION, LINE_READER::Line(), loadAliases(), loadDrawEntries(), loadField(), loadFootprintFilters(), m_aliases, m_fileName, m_versionMajor, m_versionMinor, name, parseChar(), parseInt(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_ALIAS::SetName(), LIB_FIELD::SetText(), EDA_TEXT::SetVisible(), and strCompare().

Referenced by Load().

2497 {
2498  const char* line = aReader.Line();
2499 
2500  wxCHECK( strCompare( "DEF", line, &line ), NULL );
2501 
2502  // Read DEF line:
2503  char yes_no = 0;
2504 
2505  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2506 
2507  wxString name, prefix;
2508 
2509  parseUnquotedString( name, aReader, line, &line ); // Part name.
2510  parseUnquotedString( prefix, aReader, line, &line ); // Prefix name
2511  parseInt( aReader, line, &line ); // NumOfPins, unused.
2512  part->SetPinNameOffset( parseInt( aReader, line, &line ) ); // Pin name offset.
2513  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2514 
2515  if( !( yes_no == 'Y' || yes_no == 'N') )
2516  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2517 
2518  part->SetShowPinNumbers( ( yes_no == 'N' ) ? false : true );
2519 
2520  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2521 
2522  if( !( yes_no == 'Y' || yes_no == 'N') )
2523  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2524 
2525  part->SetShowPinNames( ( yes_no == 'N' ) ? false : true ); // Show pin names.
2526 
2527  part->SetUnitCount( parseInt( aReader, line, &line ) ); // Number of units.
2528 
2529  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2530  if( part->GetUnitCount() < 1 )
2531  part->SetUnitCount( 1 );
2532 
2533  // Copy part name and prefix.
2534 
2535  // The root alias is added to the alias list by SetName() which is called by SetText().
2536  if( name.IsEmpty() )
2537  {
2538  part->SetName( "~" );
2539  }
2540  else if( name[0] != '~' )
2541  {
2542  part->SetName( name );
2543  }
2544  else
2545  {
2546  part->SetName( name.Right( name.Length() - 1 ) );
2547  part->GetValueField().SetVisible( false );
2548  }
2549 
2550  // Don't set the library alias, this is determined by the symbol library table.
2551  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2552 
2553  // There are some code paths in SetText() that do not set the root alias to the
2554  // alias list so add it here if it didn't get added by SetText().
2555  if( !part->HasAlias( part->GetName() ) )
2556  part->AddAlias( part->GetName() );
2557 
2558  LIB_FIELD& reference = part->GetReferenceField();
2559 
2560  if( prefix == "~" )
2561  {
2562  reference.Empty();
2563  reference.SetVisible( false );
2564  }
2565  else
2566  {
2567  reference.SetText( prefix );
2568  }
2569 
2570  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2571  // The was no concept of interchangeable multiple unit symbols.
2573  {
2574  // Nothing needs to be set since the default setting for symbols with multiple
2575  // units were never interchangeable. Just parse the 0 an move on.
2576  parseInt( aReader, line, &line );
2577  }
2578  else
2579  {
2580  char locked = parseChar( aReader, line, &line );
2581 
2582  if( locked == 'L' )
2583  part->LockUnits( true );
2584  else if( locked == 'F' || locked == '0' )
2585  part->LockUnits( false );
2586  else
2587  SCH_PARSE_ERROR( "expected L, F, or 0", aReader, line );
2588  }
2589 
2590 
2591  // There is the optional power component flag.
2592  if( *line )
2593  {
2594  char power = parseChar( aReader, line, &line );
2595 
2596  if( power == 'P' )
2597  part->SetPower();
2598  else if( power == 'N' )
2599  part->SetNormal();
2600  else
2601  SCH_PARSE_ERROR( "expected P or N", aReader, line );
2602  }
2603 
2604  line = aReader.ReadLine();
2605 
2606  // Read lines until "ENDDEF" is found.
2607  while( line )
2608  {
2609  if( *line == '#' ) // Comment
2610  ;
2611  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2612  continue;
2613  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2614  loadAliases( part, aReader );
2615  else if( *line == 'F' ) // Fields
2616  loadField( part, aReader );
2617  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2618  loadDrawEntries( part, aReader );
2619  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2620  loadFootprintFilters( part, aReader );
2621  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2622  {
2623  // Add aliases
2624  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2625  {
2626  LIB_ALIAS* alias = part->GetAlias( ii );
2627  const wxString& aliasName = alias->GetName();
2628  auto it = m_aliases.find( aliasName );
2629 
2630  if( it != m_aliases.end() )
2631  {
2632  // Find a new name for the alias
2633  wxString newName;
2634  int idx = 0;
2635  LIB_ALIAS_MAP::const_iterator jt;
2636 
2637  do
2638  {
2639  newName = wxString::Format( "%s_%d", aliasName, idx );
2640  jt = m_aliases.find( newName );
2641  ++idx;
2642  }
2643  while( jt != m_aliases.end() );
2644 
2645  wxLogWarning( "Symbol name conflict in library:\n%s\n"
2646  "'%s' has been renamed to '%s'",
2647  m_fileName, aliasName, newName );
2648 
2649  if( alias->IsRoot() )
2650  part->SetName( newName );
2651  else
2652  alias->SetName( newName );
2653 
2654  m_aliases[newName] = alias;
2655  }
2656  else
2657  {
2658  m_aliases[aliasName] = alias;
2659  }
2660  }
2661 
2662  return part.release();
2663  }
2664 
2665  line = aReader.ReadLine();
2666  }
2667 
2668  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2669 }
Part library alias object definition.
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static char parseChar(FILE_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.
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:173
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void loadAliases(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
bool IsRoot() const
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:502
static void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void Empty()
Definition: eda_text.h:229
Define a library symbol object.
void loadField(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
void loadDrawEntries(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
#define SCH_PARSE_ERROR(text, reader, pos)
const wxString & GetName() const
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
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 loadFootprintFilters(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_PIN * SCH_LEGACY_PLUGIN_CACHE::loadPin ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3191 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), name, parseChar(), parseInt(), parseUnquotedString(), PIN_BIDI, PIN_INPUT, PIN_INVISIBLE, PIN_NC, PIN_OPENCOLLECTOR, PIN_OPENEMITTER, PIN_OUTPUT, PIN_PASSIVE, PIN_POWER_IN, PIN_POWER_OUT, PIN_TRISTATE, PIN_UNSPECIFIED, PINSHAPE_CLOCK, PINSHAPE_CLOCK_LOW, PINSHAPE_FALLING_EDGE_CLOCK, PINSHAPE_INPUT_LOW, PINSHAPE_INVERTED, PINSHAPE_INVERTED_CLOCK, PINSHAPE_LINE, PINSHAPE_NONLOGIC, PINSHAPE_OUTPUT_LOW, SCH_PARSE_ERROR, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3193 {
3194  const char* line = aReader.Line();
3195 
3196  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3197 
3198  std::unique_ptr< LIB_PIN > pin( new LIB_PIN( aPart.get() ) );
3199 
3200  wxString name, number;
3201 
3202  parseUnquotedString( name, aReader, line, &line );
3203  parseUnquotedString( number, aReader, line, &line );
3204 
3205  // Unlike most of the other LIB_ITEMs, the SetXXX() routines on LIB_PINs are at the UI
3206  // level, performing additional pin checking, multi-pin editing, and setting the modified
3207  // flag. So we must set the member fields directly.
3208 
3209  pin->m_name = name;
3210  pin->m_number = number;
3211 
3212  wxPoint pos;
3213 
3214  pos.x = parseInt( aReader, line, &line );
3215  pos.y = parseInt( aReader, line, &line );
3216  pin->m_position = pos;
3217  pin->m_length = parseInt( aReader, line, &line );
3218  pin->m_orientation = parseChar( aReader, line, &line );
3219  pin->m_numTextSize = parseInt( aReader, line, &line );
3220  pin->m_nameTextSize = parseInt( aReader, line, &line );
3221  pin->m_Unit = parseInt( aReader, line, &line );
3222  pin->m_Convert = parseInt( aReader, line, &line );
3223 
3224  char type = parseChar( aReader, line, &line );
3225 
3226  wxString attributes;
3227 
3228  // Optional
3229  parseUnquotedString( attributes, aReader, line, &line, true );
3230 
3231  switch( type )
3232  {
3233  case 'I':
3234  pin->m_type = PIN_INPUT;
3235  break;
3236 
3237  case 'O':
3238  pin->m_type = PIN_OUTPUT;
3239  break;
3240 
3241  case 'B':
3242  pin->m_type = PIN_BIDI;
3243  break;
3244 
3245  case 'T':
3246  pin->m_type = PIN_TRISTATE;
3247  break;
3248 
3249  case 'P':
3250  pin->m_type = PIN_PASSIVE;
3251  break;
3252 
3253  case 'U':
3254  pin->m_type = PIN_UNSPECIFIED;
3255  break;
3256 
3257  case 'W':
3258  pin->m_type = PIN_POWER_IN;
3259  break;
3260 
3261  case 'w':
3262  pin->m_type = PIN_POWER_OUT;
3263  break;
3264 
3265  case 'C':
3266  pin->m_type = PIN_OPENCOLLECTOR;
3267  break;
3268 
3269  case 'E':
3270  pin->m_type = PIN_OPENEMITTER;
3271  break;
3272 
3273  case 'N':
3274  pin->m_type = PIN_NC;
3275  break;
3276 
3277  default:
3278  SCH_PARSE_ERROR( "unknown pin type", aReader, line );
3279  }
3280 
3281  if( !attributes.IsEmpty() ) /* Special Symbol defined */
3282  {
3283  enum
3284  {
3285  INVERTED = 1 << 0,
3286  CLOCK = 1 << 1,
3287  LOWLEVEL_IN = 1 << 2,
3288  LOWLEVEL_OUT = 1 << 3,
3289  FALLING_EDGE = 1 << 4,
3290  NONLOGIC = 1 << 5
3291  };
3292 
3293  int flags = 0;
3294 
3295  for( int j = attributes.size(); j > 0; )
3296  {
3297  switch( attributes[--j].GetValue() )
3298  {
3299  case '~':
3300  break;
3301 
3302  case 'N':
3303  pin->m_attributes |= PIN_INVISIBLE;
3304  break;
3305 
3306  case 'I':
3307  flags |= INVERTED;
3308  break;
3309 
3310  case 'C':
3311  flags |= CLOCK;
3312  break;
3313 
3314  case 'L':
3315  flags |= LOWLEVEL_IN;
3316  break;
3317 
3318  case 'V':
3319  flags |= LOWLEVEL_OUT;
3320  break;
3321 
3322  case 'F':
3323  flags |= FALLING_EDGE;
3324  break;
3325 
3326  case 'X':
3327  flags |= NONLOGIC;
3328  break;
3329 
3330  default:
3331  SCH_PARSE_ERROR( "unknown pin attribute", aReader, line );
3332  }
3333  }
3334 
3335  switch( flags )
3336  {
3337  case 0:
3338  pin->m_shape = PINSHAPE_LINE;
3339  break;
3340 
3341  case INVERTED:
3342  pin->m_shape = PINSHAPE_INVERTED;
3343  break;
3344 
3345  case CLOCK:
3346  pin->m_shape = PINSHAPE_CLOCK;
3347  break;
3348 
3349  case INVERTED | CLOCK:
3350  pin->m_shape = PINSHAPE_INVERTED_CLOCK;
3351  break;
3352 
3353  case LOWLEVEL_IN:
3354  pin->m_shape = PINSHAPE_INPUT_LOW;
3355  break;
3356 
3357  case LOWLEVEL_IN | CLOCK:
3358  pin->m_shape = PINSHAPE_CLOCK_LOW;
3359  break;
3360 
3361  case LOWLEVEL_OUT:
3362  pin->m_shape = PINSHAPE_OUTPUT_LOW;
3363  break;
3364 
3365  case FALLING_EDGE:
3366  pin->m_shape = PINSHAPE_FALLING_EDGE_CLOCK;
3367  break;
3368 
3369  case NONLOGIC:
3370  pin->m_shape = PINSHAPE_NONLOGIC;
3371  break;
3372 
3373  default:
3374  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3375  }
3376  }
3377 
3378  return pin.release();
3379 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static char parseChar(FILE_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 void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define PIN_INVISIBLE
Definition: lib_pin.h:46
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:61
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_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3382 of file sch_legacy_plugin.cpp.

References i, LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3384 {
3385  const char* line = aReader.Line();
3386 
3387  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3388 
3389  std::unique_ptr< LIB_POLYLINE > polyLine( new LIB_POLYLINE( aPart.get() ) );
3390 
3391  int points = parseInt( aReader, line, &line );
3392  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3393  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3394  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3395 
3396  wxPoint pt;
3397 
3398  for( int i = 0; i < points; i++ )
3399  {
3400  pt.x = parseInt( aReader, line, &line );
3401  pt.y = parseInt( aReader, line, &line );
3402  polyLine->AddPoint( pt );
3403  }
3404 
3405  if( *line != 0 )
3406  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3407 
3408  return polyLine.release();
3409 }
static int parseInt(FILE_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...
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
size_t i
Definition: json11.cpp:597
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_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3159 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3161 {
3162  const char* line = aReader.Line();
3163 
3164  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3165 
3166  std::unique_ptr< LIB_RECTANGLE > rectangle( new LIB_RECTANGLE( aPart.get() ) );
3167 
3168  wxPoint pos;
3169 
3170  pos.x = parseInt( aReader, line, &line );
3171  pos.y = parseInt( aReader, line, &line );
3172  rectangle->SetPosition( pos );
3173 
3174  wxPoint end;
3175 
3176  end.x = parseInt( aReader, line, &line );
3177  end.y = parseInt( aReader, line, &line );
3178  rectangle->SetEnd( end );
3179 
3180  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3181  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3182  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3183 
3184  if( *line != 0 )
3185  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3186 
3187  return rectangle.release();
3188 }
static int parseInt(FILE_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...
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_TEXT * SCH_LEGACY_PLUGIN_CACHE::loadText ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3048 of file sch_legacy_plugin.cpp.

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(), m_versionMajor, m_versionMinor, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, str, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries(), and SCH_LEGACY_PLUGIN::loadFile().

3050 {
3051  const char* line = aReader.Line();
3052 
3053  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3054 
3055  std::unique_ptr< LIB_TEXT > text( new LIB_TEXT( aPart.get() ) );
3056 
3057  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3058 
3059  wxPoint center;
3060 
3061  center.x = parseInt( aReader, line, &line );
3062  center.y = parseInt( aReader, line, &line );
3063  text->SetPosition( center );
3064 
3065  wxSize size;
3066 
3067  size.x = size.y = parseInt( aReader, line, &line );
3068  text->SetTextSize( size );
3069  text->SetVisible( !parseInt( aReader, line, &line ) );
3070  text->SetUnit( parseInt( aReader, line, &line ) );
3071  text->SetConvert( parseInt( aReader, line, &line ) );
3072 
3073  wxString str;
3074 
3075  // If quoted string loading fails, load as not quoted string.
3076  if( *line == '"' )
3077  parseQuotedString( str, aReader, line, &line );
3078  else
3079  {
3080  parseUnquotedString( str, aReader, line, &line );
3081 
3082  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3083  str.Replace( "~", " " );
3084  }
3085 
3086  if( !str.IsEmpty() )
3087  {
3088  // convert two apostrophes back to double quote
3089  str.Replace( "''", "\"" );
3090  }
3091 
3092  text->SetText( str );
3093 
3094  // Here things are murky and not well defined. At some point it appears the format
3095  // was changed to add text properties. However rather than add the token to the end of
3096  // the text definition, it was added after the string and no mention if the file
3097  // verion was bumped or not so this code make break on very old component libraries.
3098  //
3099  // Update: apparently even in the latest version this can be different so added a test
3100  // for end of line before checking for the text properties.
3101  if( LIB_VERSION( m_versionMajor, m_versionMinor ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3102  {
3103  if( strCompare( "Italic", line, &line ) )
3104  text->SetItalic( true );
3105  else if( !strCompare( "Normal", line, &line ) )
3106  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'",
3107  aReader, line );
3108 
3109  if( parseInt( aReader, line, &line ) > 0 )
3110  text->SetBold( true );
3111 
3112  // Some old libaries version > 2.0 do not have these options for text justification:
3113  if( !is_eol( *line ) )
3114  {
3115  switch( parseChar( aReader, line, &line ) )
3116  {
3117  case 'L':
3118  text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
3119  break;
3120 
3121  case 'C':
3122  text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
3123  break;
3124 
3125  case 'R':
3126  text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
3127  break;
3128 
3129  default:
3130  SCH_PARSE_ERROR( "invalid horizontal text justication parameter, expected L, C, or R",
3131  aReader, line );
3132  }
3133 
3134  switch( parseChar( aReader, line, &line ) )
3135  {
3136  case 'T':
3137  text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
3138  break;
3139 
3140  case 'C':
3141  text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
3142  break;
3143 
3144  case 'B':
3145  text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
3146  break;
3147 
3148  default:
3149  SCH_PARSE_ERROR( "invalid vertical text justication parameter, expected T, C, or B",
3150  aReader, line );
3151  }
3152  }
3153  }
3154 
3155  return text.release();
3156 }
static int parseInt(FILE_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 a symbol library graphical text item.
Definition: lib_text.h:44
static char parseChar(FILE_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 LIB_VERSION(major, minor)
Definition: class_library.h:61
const string & str
Definition: json11.cpp:596
static void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static bool is_eol(char c)
#define SCH_PARSE_ERROR(text, reader, pos)
static void parseQuotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
static 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...
FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode ( FILE_LINE_READER aReader,
const char *  aLine,
const char **  aOutput 
)
private

Definition at line 2928 of file sch_legacy_plugin.cpp.

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

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

2930 {
2931  FILL_T mode;
2932 
2933  switch( parseChar( aReader, aLine, aOutput ) )
2934  {
2935  case 'F':
2936  mode = FILLED_SHAPE;
2937  break;
2938 
2939  case 'f':
2940  mode = FILLED_WITH_BG_BODYCOLOR;
2941  break;
2942 
2943  case 'N':
2944  mode = NO_FILL;
2945  break;
2946 
2947  default:
2948  SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
2949  }
2950 
2951  return mode;
2952 }
static char parseChar(FILE_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)
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:52
LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

Definition at line 2232 of file sch_legacy_plugin.cpp.

References LIB_ALIAS::GetName(), m_aliases, m_isModified, m_libFileName, m_modHash, next(), and LIB_PART::RemoveAlias().

Referenced by AddSymbol().

2233 {
2234  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2235 
2236  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2237 
2238  if( it == m_aliases.end() )
2239  return NULL;
2240 
2241  // If the entry pointer doesn't match the name it is mapped to in the library, we
2242  // have done something terribly wrong.
2243  wxCHECK_MSG( *it->second == aAlias, NULL,
2244  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2245  "> from library cache <" + m_libFileName.GetName() + ">." );
2246 
2247  LIB_ALIAS* alias = aAlias;
2248  LIB_PART* part = alias->GetPart();
2249 
2250  alias = part->RemoveAlias( alias );
2251 
2252  if( !alias )
2253  {
2254  delete part;
2255 
2256  if( m_aliases.size() > 1 )
2257  {
2258  LIB_ALIAS_MAP::iterator next = it;
2259  next++;
2260 
2261  if( next == m_aliases.end() )
2262  next = m_aliases.begin();
2263 
2264  alias = next->second;
2265  }
2266  }
2267 
2268  m_aliases.erase( it );
2269  m_isModified = true;
2270  ++m_modHash;
2271  return alias;
2272 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol object.
void RemoveAlias(const wxString &aName)
const wxString & GetName() const
void SCH_LEGACY_PLUGIN_CACHE::Save ( bool  aSaveDocFile = true)

Save the entire library to file m_libFileName;.

Definition at line 3467 of file sch_legacy_plugin.cpp.

References LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIBFILE_IDENT, m_aliases, m_fileModTime, m_isModified, m_libFileName, saveDocFile(), and saveSymbol().

Referenced by GetModifyHash().

3468 {
3469  if( !m_isModified )
3470  return;
3471 
3472  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( m_libFileName.GetFullPath() ) );
3473  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3474  formatter->Print( 0, "#encoding utf-8\n");
3475 
3476  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3477  {
3478  if( !it->second->IsRoot() )
3479  continue;
3480 
3481  saveSymbol( it->second->GetPart(), formatter );
3482  }
3483 
3484  formatter->Print( 0, "#\n#End Library\n" );
3485  formatter.reset();
3486 
3487  m_fileModTime = m_libFileName.GetModificationTime();
3488  m_isModified = false;
3489 
3490  if( aSaveDocFile )
3491  saveDocFile();
3492 }
#define LIBFILE_IDENT
Definition: class_library.h:59
#define LIB_VERSION_MINOR
Definition: class_library.h:56
#define LIB_VERSION_MAJOR
Definition: class_library.h:55
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
void saveSymbol(LIB_PART *aSymbol, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void SCH_LEGACY_PLUGIN_CACHE::saveArc ( LIB_ARC aArc,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3665 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3667 {
3668  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3669 
3670  int x1 = aArc->GetFirstRadiusAngle();
3671 
3672  if( x1 > 1800 )
3673  x1 -= 3600;
3674 
3675  int x2 = aArc->GetSecondRadiusAngle();
3676 
3677  if( x2 > 1800 )
3678  x2 -= 3600;
3679 
3680  aFormatter->Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3681  aArc->GetPosition().x, aArc->GetPosition().y,
3682  aArc->GetRadius(), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3683  aArc->GetWidth(), fill_tab[aArc->GetFillMode()],
3684  aArc->GetStart().x, aArc->GetStart().y,
3685  aArc->GetEnd().x, aArc->GetEnd().y );
3686 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetSecondRadiusAngle() const
Definition: lib_arc.h:146
wxPoint GetStart() const
Definition: lib_arc.h:148
int GetUnit() const
int GetFirstRadiusAngle() const
Definition: lib_arc.h:142
wxPoint GetEnd() const
Definition: lib_arc.h:152
int GetRadius() const
Definition: lib_arc.h:138
int GetWidth() const override
Return the width of the draw item.
Definition: lib_arc.h:132
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_arc.h:121
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveBezier ( LIB_BEZIER aBezier,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3689 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3691 {
3692  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3693 
3694  aFormatter->Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3695  aBezier->GetUnit(), aBezier->GetConvert(), aBezier->GetWidth() );
3696 
3697  for( const auto& pt : aBezier->GetPoints() )
3698  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3699 
3700  aFormatter->Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3701 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:75
int GetWidth() const override
Return the width of the draw item.
Definition: lib_bezier.h:101
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveCircle ( LIB_CIRCLE aCircle,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3704 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3706 {
3707  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3708 
3709  aFormatter->Print( 0, "C %d %d %d %d %d %d %c\n",
3710  aCircle->GetPosition().x, aCircle->GetPosition().y,
3711  aCircle->GetRadius(), aCircle->GetUnit(), aCircle->GetConvert(),
3712  aCircle->GetWidth(), fill_tab[aCircle->GetFillMode()] );
3713 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_circle.h:86
int GetWidth() const override
Return the width of the draw item.
Definition: lib_circle.h:97
int GetRadius() const
Definition: lib_circle.h:103
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 3955 of file sch_legacy_plugin.cpp.

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

Referenced by Save().

3956 {
3957  wxFileName fileName = m_libFileName;
3958 
3959  fileName.SetExt( DOC_EXT );
3960  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
3961 
3962  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
3963 
3964  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3965  {
3966  wxString description = it->second->GetDescription();
3967  wxString keyWords = it->second->GetKeyWords();
3968  wxString docFileName = it->second->GetDocFileName();
3969 
3970  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
3971  continue;
3972 
3973  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
3974 
3975  if( !description.IsEmpty() )
3976  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
3977 
3978  if( !keyWords.IsEmpty() )
3979  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
3980 
3981  if( !docFileName.IsEmpty() )
3982  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
3983 
3984  formatter.Print( 0, "$ENDCMP\n" );
3985  }
3986 
3987  formatter.Print( 0, "#\n#End Doc Library\n" );
3988 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:50
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void SCH_LEGACY_PLUGIN_CACHE::saveField ( LIB_FIELD aField,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3716 of file sch_legacy_plugin.cpp.

References EscapedUTF8(), FIELD1, TEMPLATE_FIELDNAME::GetDefaultFieldName(), EDA_TEXT::GetHorizJustify(), LIB_FIELD::GetId(), 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(), LIB_FIELD::IsVisible(), LIB_FIELD_T, LIB_FIELD::m_name, EDA_TEXT::m_Text, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SCH_LEGACY_PLUGIN::saveComponent(), and saveSymbol().

3718 {
3719  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3720 
3721  int hjustify, vjustify;
3722  int id = aField->GetId();
3723  wxString text = aField->m_Text;
3724 
3725  hjustify = 'C';
3726 
3727  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3728  hjustify = 'L';
3729  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3730  hjustify = 'R';
3731 
3732  vjustify = 'C';
3733 
3734  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3735  vjustify = 'B';
3736  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3737  vjustify = 'T';
3738 
3739  aFormatter->Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3740  id,
3741  EscapedUTF8( text ).c_str(), // wraps in quotes
3742  aField->GetTextPos().x, aField->GetTextPos().y, aField->GetTextWidth(),
3743  aField->GetTextAngle() == 0 ? 'H' : 'V',
3744  aField->IsVisible() ? 'V' : 'I',
3745  hjustify, vjustify,
3746  aField->IsItalic() ? 'I' : 'N',
3747  aField->IsBold() ? 'B' : 'N' );
3748 
3749  /* Save field name, if necessary
3750  * Field name is saved only if it is not the default name.
3751  * Just because default name depends on the language and can change from
3752  * a country to another
3753  */
3754  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3755 
3756  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3757  aFormatter->Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3758 
3759  aFormatter->Print( 0, "\n" );
3760 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
wxString m_Text
Definition: eda_text.h:344
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
bool IsItalic() const
Definition: eda_text.h:168
int GetTextWidth() const
Definition: eda_text.h:216
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:137
int GetId() const
Definition: lib_field.h:138
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
bool IsVisible() const
Definition: lib_field.h:164
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void SCH_LEGACY_PLUGIN_CACHE::savePin ( LIB_PIN aPin,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3763 of file sch_legacy_plugin.cpp.

References EDA_ITEM::ClearFlags(), 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(), IS_CHANGED, LIB_PIN::IsVisible(), LIB_PIN_T, PIN_BIDI, PIN_INPUT, PIN_NC, PIN_OPENCOLLECTOR, PIN_OPENEMITTER, PIN_OUTPUT, PIN_PASSIVE, PIN_POWER_IN, PIN_POWER_OUT, PIN_TRISTATE, PIN_UNSPECIFIED, PINSHAPE_CLOCK, PINSHAPE_CLOCK_LOW, PINSHAPE_FALLING_EDGE_CLOCK, PINSHAPE_INPUT_LOW, PINSHAPE_INVERTED, PINSHAPE_INVERTED_CLOCK, PINSHAPE_LINE, PINSHAPE_NONLOGIC, PINSHAPE_OUTPUT_LOW, TO_UTF8, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveSymbol().

3765 {
3766  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3767 
3768  int Etype;
3769 
3770  switch( aPin->GetType() )
3771  {
3772  default:
3773  case PIN_INPUT:
3774  Etype = 'I';
3775  break;
3776 
3777  case PIN_OUTPUT:
3778  Etype = 'O';
3779  break;
3780 
3781  case PIN_BIDI:
3782  Etype = 'B';
3783  break;
3784 
3785  case PIN_TRISTATE:
3786  Etype = 'T';
3787  break;
3788 
3789  case PIN_PASSIVE:
3790  Etype = 'P';
3791  break;
3792 
3793  case PIN_UNSPECIFIED:
3794  Etype = 'U';
3795  break;
3796 
3797  case PIN_POWER_IN:
3798  Etype = 'W';
3799  break;
3800 
3801  case PIN_POWER_OUT:
3802  Etype = 'w';
3803  break;
3804 
3805  case PIN_OPENCOLLECTOR:
3806  Etype = 'C';
3807  break;
3808 
3809  case PIN_OPENEMITTER:
3810  Etype = 'E';
3811  break;
3812 
3813  case PIN_NC:
3814  Etype = 'N';
3815  break;
3816  }
3817 
3818  if( !aPin->GetName().IsEmpty() )
3819  aFormatter->Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
3820  else
3821  aFormatter->Print( 0, "X ~" );
3822 
3823  aFormatter->Print( 0, " %s %d %d %d %c %d %d %d %d %c",
3824  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
3825  aPin->GetPosition().x, aPin->GetPosition().y,
3826  (int) aPin->GetLength(), (int) aPin->GetOrientation(),
3827  aPin->GetNumberTextSize(), aPin->GetNameTextSize(),
3828  aPin->GetUnit(), aPin->GetConvert(), Etype );
3829 
3830  if( aPin->GetShape() || !aPin->IsVisible() )
3831  aFormatter->Print( 0, " " );
3832 
3833  if( !aPin->IsVisible() )
3834  aFormatter->Print( 0, "N" );
3835 
3836  switch( aPin->GetShape() )
3837  {
3838  case PINSHAPE_LINE:
3839  break;
3840 
3841  case PINSHAPE_INVERTED:
3842  aFormatter->Print( 0, "I" );
3843  break;
3844 
3845  case PINSHAPE_CLOCK:
3846  aFormatter->Print( 0, "C" );
3847  break;
3848 
3850  aFormatter->Print( 0, "IC" );
3851  break;
3852 
3853  case PINSHAPE_INPUT_LOW:
3854  aFormatter->Print( 0, "L" );
3855  break;
3856 
3857  case PINSHAPE_CLOCK_LOW:
3858  aFormatter->Print( 0, "CL" );
3859  break;
3860 
3861  case PINSHAPE_OUTPUT_LOW:
3862  aFormatter->Print( 0, "V" );
3863  break;
3864 
3866  aFormatter->Print( 0, "F" );
3867  break;
3868 
3869  case PINSHAPE_NONLOGIC:
3870  aFormatter->Print( 0, "X" );
3871  break;
3872 
3873  default:
3874  assert( !"Invalid pin shape" );
3875  }
3876 
3877  aFormatter->Print( 0, "\n" );
3878 
3879  aPin->ClearFlags( IS_CHANGED );
3880 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
int GetUnit() const
int GetNameTextSize() const
Definition: lib_pin.h:191
int GetOrientation() const
Definition: lib_pin.h:220
int GetNumberTextSize() const
Definition: lib_pin.h:218
const wxString & GetNumber() const
Definition: lib_pin.h:193
const wxString & GetName() const
Definition: lib_pin.h:165
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:105
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:250
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:361
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:462
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
int GetLength()
Definition: lib_pin.h:300
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:234
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::savePolyLine ( LIB_POLYLINE aPolyLine,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3883 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3885 {
3886  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
3887 
3888  int ccount = aPolyLine->GetCornerCount();
3889 
3890  aFormatter->Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
3891  aPolyLine->GetWidth() );
3892 
3893  for( const auto& pt : aPolyLine->GetPolyPoints() )
3894  {
3895  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3896  }
3897 
3898  aFormatter->Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
3899 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:67
unsigned GetCornerCount() const
Definition: lib_polyline.h:77
int GetWidth() const override
Return the width of the draw item.
Definition: lib_polyline.h:112
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveRectangle ( LIB_RECTANGLE aRectangle,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3902 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3904 {
3905  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
3906  "Invalid LIB_RECTANGLE object." );
3907 
3908  aFormatter->Print( 0, "S %d %d %d %d %d %d %d %c\n",
3909  aRectangle->GetPosition().x, aRectangle->GetPosition().y,
3910  aRectangle->GetEnd().x, aRectangle->GetEnd().y,
3911  aRectangle->GetUnit(), aRectangle->GetConvert(),
3912  aRectangle->GetWidth(), fill_tab[aRectangle->GetFillMode()] );
3913 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
int GetWidth() const override
Return the width of the draw item.
wxPoint GetEnd() const
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_rectangle.h:91
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveSymbol ( LIB_PART aSymbol,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3495 of file sch_legacy_plugin.cpp.

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_PART::GetAliasCount(), LIB_PART::GetAliasNames(), LIB_PART::GetDateLastEdition(), LIB_PART::GetDrawItems(), LIB_PART::GetFields(), LIB_PART::GetFootprints(), LIB_PART::GetPinNameOffset(), LIB_PART::GetReferenceField(), GetText(), EDA_TEXT::GetText(), LIB_PART::GetUnitCount(), LIB_PART::GetValueField(), i, LIB_PART::IsPower(), LIB_FIELD::IsVisible(), 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, min, saveArc(), saveBezier(), saveCircle(), saveField(), savePin(), savePolyLine(), saveRectangle(), saveText(), LIB_PART::ShowPinNames(), LIB_PART::ShowPinNumbers(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort(), TO_UTF8, and LIB_PART::UnitsLocked().

Referenced by Save().

3497 {
3498  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
3499 
3500  LIB_FIELD& value = aSymbol->GetValueField();
3501 
3502  // First line: it s a comment (component name for readers)
3503  aFormatter->Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3504 
3505  // Save data
3506  aFormatter->Print( 0, "DEF" );
3507 
3508  if( value.IsVisible() )
3509  {
3510  aFormatter->Print( 0, " %s", TO_UTF8( value.GetText() ) );
3511  }
3512  else
3513  {
3514  aFormatter->Print( 0, " ~%s", TO_UTF8( value.GetText() ) );
3515  }
3516 
3517  LIB_FIELD& reference = aSymbol->GetReferenceField();
3518 
3519  if( !reference.GetText().IsEmpty() )
3520  {
3521  aFormatter->Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3522  }
3523  else
3524  {
3525  aFormatter->Print( 0, " ~" );
3526  }
3527 
3528  aFormatter->Print( 0, " %d %d %c %c %d %c %c\n",
3529  0, aSymbol->GetPinNameOffset(),
3530  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3531  aSymbol->ShowPinNames() ? 'Y' : 'N',
3532  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3533  aSymbol->IsPower() ? 'P' : 'N' );
3534 
3535  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3536 
3537  if( dateModified != 0 )
3538  {
3539  int sec = dateModified & 63;
3540  int min = ( dateModified >> 6 ) & 63;
3541  int hour = ( dateModified >> 12 ) & 31;
3542  int day = ( dateModified >> 17 ) & 31;
3543  int mon = ( dateModified >> 22 ) & 15;
3544  int year = ( dateModified >> 26 ) + 1990;
3545 
3546  aFormatter->Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3547  }
3548 
3549  LIB_FIELDS fields;
3550  aSymbol->GetFields( fields );
3551 
3552  // Mandatory fields:
3553  // may have their own save policy so there is a separate loop for them.
3554  // Empty fields are saved, because the user may have set visibility,
3555  // size and orientation
3556  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3557  {
3558  saveField( &fields[i], aFormatter );
3559  }
3560 
3561  // User defined fields:
3562  // may have their own save policy so there is a separate loop for them.
3563 
3564  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3565 
3566  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3567  {
3568  // There is no need to save empty fields, i.e. no reason to preserve field
3569  // names now that fields names come in dynamically through the template
3570  // fieldnames.
3571  if( !fields[i].GetText().IsEmpty() )
3572  {
3573  fields[i].SetId( fieldId++ );
3574  saveField( &fields[i], aFormatter );
3575  }
3576  }
3577 
3578  // Save the alias list: a line starting by "ALIAS". The first alias is the root
3579  // and has the same name as the component. In the old library file format this
3580  // alias does not get added to the alias list.
3581  if( aSymbol->GetAliasCount() > 1 )
3582  {
3583  wxArrayString aliases = aSymbol->GetAliasNames();
3584 
3585  aFormatter->Print( 0, "ALIAS" );
3586 
3587  for( unsigned i = 1; i < aliases.size(); i++ )
3588  {
3589  aFormatter->Print( 0, " %s", TO_UTF8( aliases[i] ) );
3590  }
3591 
3592  aFormatter->Print( 0, "\n" );
3593  }
3594 
3595  wxArrayString footprints = aSymbol->GetFootprints();
3596 
3597  // Write the footprint filter list
3598  if( footprints.GetCount() != 0 )
3599  {
3600  aFormatter->Print( 0, "$FPLIST\n" );
3601 
3602  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3603  {
3604  aFormatter->Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3605  }
3606 
3607  aFormatter->Print( 0, "$ENDFPLIST\n" );
3608  }
3609 
3610  // Save graphics items (including pins)
3611  if( !aSymbol->GetDrawItems().empty() )
3612  {
3613  // Sort the draw items in order to editing a file editing by hand.
3614  aSymbol->GetDrawItems().sort();
3615 
3616  aFormatter->Print( 0, "DRAW\n" );
3617 
3618  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3619  {
3620  switch( item.Type() )
3621  {
3622  case LIB_FIELD_T: // Fields have already been saved above.
3623  continue;
3624 
3625  case LIB_ARC_T:
3626  saveArc( (LIB_ARC*) &item, aFormatter );
3627  break;
3628 
3629  case LIB_BEZIER_T:
3630  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3631  break;
3632 
3633  case LIB_CIRCLE_T:
3634  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3635  break;
3636 
3637  case LIB_PIN_T:
3638  savePin( (LIB_PIN* ) &item, aFormatter );
3639  break;
3640 
3641  case LIB_POLYLINE_T:
3642  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3643  break;
3644 
3645  case LIB_RECTANGLE_T:
3646  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3647  break;
3648 
3649  case LIB_TEXT_T:
3650  saveText( ( LIB_TEXT* ) &item, aFormatter );
3651  break;
3652 
3653  default:
3654  ;
3655  }
3656  }
3657 
3658  aFormatter->Print( 0, "ENDDRAW\n" );
3659  }
3660 
3661  aFormatter->Print( 0, "ENDDEF\n" );
3662 }
bool UnitsLocked() const
Check whether part units are interchangeable.
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: base_struct.h:155
int GetPinNameOffset()
bool IsPower() const
Define a symbol library graphical text item.
Definition: lib_text.h:44
void saveRectangle(LIB_RECTANGLE *aRectangle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
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:229
LIB_FIELD & GetValueField()
Return reference to the value field.
size_t GetAliasCount() const
void savePin(LIB_PIN *aPin, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveCircle(LIB_CIRCLE *aCircle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
void saveText(LIB_TEXT *aText, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
bool ShowPinNames()
bool ShowPinNumbers()
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
timestamp_t GetDateLastEdition() const
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
wxArrayString & GetFootprints()
int GetUnitCount() const
bool IsVisible() const
Definition: lib_field.h:164
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:257
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
void savePolyLine(LIB_POLYLINE *aPolyLine, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveArc(LIB_ARC *aArc, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveField(LIB_FIELD *aField, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveBezier(LIB_BEZIER *aBezier, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void GetFields(LIB_FIELDS &aList)
Return a list of fields withing this part.
#define min(a, b)
Definition: auxiliary.h:85
Class LIB_BEZIER defines bezier curve graphic body item.
Definition: lib_bezier.h:39
void SCH_LEGACY_PLUGIN_CACHE::saveText ( LIB_TEXT aText,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3916 of file sch_legacy_plugin.cpp.

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

Referenced by SCH_LEGACY_PLUGIN::Format(), and saveSymbol().

3918 {
3919  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
3920 
3921  wxString text = aText->GetText();
3922 
3923  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
3924  {
3925  // convert double quote to similar-looking two apostrophes
3926  text.Replace( wxT( "\"" ), wxT( "''" ) );
3927  text = wxT( "\"" ) + text + wxT( "\"" );
3928  }
3929 
3930  aFormatter->Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
3931  aText->GetTextPos().x, aText->GetTextPos().y,
3932  aText->GetTextWidth(), !aText->IsVisible(),
3933  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
3934 
3935  aFormatter->Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
3936 
3937  char hjustify = 'C';
3938 
3939  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3940  hjustify = 'L';
3941  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3942  hjustify = 'R';
3943 
3944  char vjustify = 'C';
3945 
3946  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3947  vjustify = 'B';
3948  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3949  vjustify = 'T';
3950 
3951  aFormatter->Print( 0, " %c %c\n", hjustify, vjustify );
3952 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
bool IsItalic() const
Definition: eda_text.h:168
int GetUnit() const
int GetTextWidth() const
Definition: eda_text.h:216
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
bool IsVisible() const
Definition: eda_text.h:174
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 551 of file sch_legacy_plugin.cpp.

551 { m_libFileName = aFileName; }
void SCH_LEGACY_PLUGIN_CACHE::SetModified ( bool  aModified = true)
inline

Definition at line 547 of file sch_legacy_plugin.cpp.

547 { m_isModified = aModified; }

Member Data Documentation

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 470 of file sch_legacy_plugin.cpp.

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

wxString SCH_LEGACY_PLUGIN_CACHE::m_fileName
private

Definition at line 468 of file sch_legacy_plugin.cpp.

Referenced by IsFile(), and loadPart().

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 473 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteAlias(), removeAlias(), and Save().

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 472 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

wxFileName SCH_LEGACY_PLUGIN_CACHE::m_libFileName
private
int SCH_LEGACY_PLUGIN_CACHE::m_libType
private

Definition at line 476 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

int SCH_LEGACY_PLUGIN_CACHE::m_modHash = 1
staticprivate
int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 474 of file sch_legacy_plugin.cpp.

Referenced by Load(), loadPart(), loadText(), and SCH_LEGACY_PLUGIN_CACHE().

int SCH_LEGACY_PLUGIN_CACHE::m_versionMinor
private

Definition at line 475 of file sch_legacy_plugin.cpp.

Referenced by Load(), loadPart(), loadText(), and SCH_LEGACY_PLUGIN_CACHE().

friend SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN
private

Definition at line 518 of file sch_legacy_plugin.cpp.


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