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

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

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

2154 {
2155  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2156  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2157  {
2158  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2159  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2160  LIB_PART* part = it->second->GetPart();
2161  LIB_ALIAS* alias = it->second;
2162  delete alias;
2163 
2164  // When the last alias of a part is destroyed, the part is no longer required and it
2165  // too is destroyed.
2166  if( part && part->GetAliasCount() == 0 )
2167  delete part;
2168  }
2169 
2170  m_aliases.clear();
2171 }
Part library alias object definition.
size_t GetAliasCount() const
const wxChar traceSchLegacyPlugin[]
Flag to enable legacy schematic plugin debug output.
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 2242 of file sch_legacy_plugin.cpp.

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

Referenced by SCH_LEGACY_PLUGIN::SaveSymbol().

2243 {
2244  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2245  wxArrayString aliasNames = aPart->GetAliasNames();
2246 
2247  for( size_t i = 0; i < aliasNames.size(); i++ )
2248  {
2249  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2250 
2251  if( it != m_aliases.end() )
2252  removeAlias( it->second );
2253 
2254  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2255 
2256  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2257  aPart->GetName() +">." );
2258 
2259  m_aliases[ aliasNames[i] ] = alias;
2260  }
2261 
2262  m_isModified = true;
2263  ++m_modHash;
2264 }
Part library alias object definition.
const wxString & GetName() const
Define a library symbol object.
LIB_ALIAS * removeAlias(LIB_ALIAS *aAlias)
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
bool SCH_LEGACY_PLUGIN_CACHE::checkForDuplicates ( wxString &  aAliasName)
private

Definition at line 2605 of file sch_legacy_plugin.cpp.

References m_aliases.

Referenced by loadAliases().

2606 {
2607  wxCHECK_MSG( !aAliasName.IsEmpty(), false, "alias name cannot be empty" );
2608 
2609  // The alias name is not a duplicate so don't change it.
2610  if( m_aliases.find( aAliasName ) == m_aliases.end() )
2611  return false;
2612 
2613  int dupCounter = 1;
2614  wxString newAlias = aAliasName;
2615 
2616  // If the alias is already loaded, the library is broken. It may have been possible in
2617  // the past that this could happen so we assign a new alias name to prevent any conflicts
2618  // rather than throw an exception.
2619  while( m_aliases.find( newAlias ) != m_aliases.end() )
2620  {
2621  newAlias = aAliasName << dupCounter;
2622  dupCounter++;
2623  }
2624 
2625  aAliasName = newAlias;
2626 
2627  return true;
2628 }
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

Definition at line 3925 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 SCH_LEGACY_PLUGIN::DeleteAlias(), and DeleteSymbol().

3926 {
3927  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3928 
3929  if( it == m_aliases.end() )
3930  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3931  m_libFileName.GetFullName(), aAliasName ) );
3932 
3933  LIB_ALIAS* alias = it->second;
3934  LIB_PART* part = alias->GetPart();
3935 
3936  alias = part->RemoveAlias( alias );
3937 
3938  if( !alias )
3939  {
3940  delete part;
3941 
3942  if( m_aliases.size() > 1 )
3943  {
3944  LIB_ALIAS_MAP::iterator next = it;
3945  next++;
3946 
3947  if( next == m_aliases.end() )
3948  next = m_aliases.begin();
3949 
3950  alias = next->second;
3951  }
3952  }
3953 
3954  m_aliases.erase( it );
3955  ++m_modHash;
3956  m_isModified = true;
3957 }
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 3960 of file sch_legacy_plugin.cpp.

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

Referenced by SCH_LEGACY_PLUGIN::DeleteSymbol().

3961 {
3962  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3963 
3964  if( it == m_aliases.end() )
3965  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3966  m_libFileName.GetFullName(), aAliasName ) );
3967 
3968  LIB_ALIAS* alias = it->second;
3969  LIB_PART* part = alias->GetPart();
3970 
3971  wxArrayString aliasNames = part->GetAliasNames();
3972 
3973  // Deleting all of the aliases deletes the symbol from the library.
3974  for( size_t i = 0; i < aliasNames.Count(); i++ )
3975  DeleteAlias( aliasNames[i] );
3976 }
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 558 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

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

Definition at line 2174 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by Load().

2175 {
2176  // update the writable flag while we have a wxFileName, in a network this
2177  // is possibly quite dynamic anyway.
2178  m_isWritable = m_libFileName.IsFileWritable();
2179 
2180  return m_libFileName.GetModificationTime();
2181 }
wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 554 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

554 { return m_libFileName.GetName(); }
int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline

Definition at line 529 of file sch_legacy_plugin.cpp.

References m_modHash.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

529 { return m_modHash; }
bool SCH_LEGACY_PLUGIN_CACHE::IsFile ( const wxString &  aFullPathAndFileName) const

Definition at line 2184 of file sch_legacy_plugin.cpp.

References m_libFileName.

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

2185 {
2186  return m_libFileName == aFullPathAndFileName;
2187 }
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2190 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

2191 {
2192  if( m_fileModTime.IsValid() && m_libFileName.IsOk() && m_libFileName.FileExists() )
2193  return m_libFileName.GetModificationTime() != m_fileModTime;
2194 
2195  return false;
2196 }
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 2267 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 SCH_LEGACY_PLUGIN::cacheLib(), and SCH_LEGACY_PLUGIN::CreateSymbolLib().

2268 {
2269  wxCHECK_RET( m_libFileName.IsAbsolute(),
2270  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2271  "open library '%s'.", m_libFileName.GetFullPath() ) );
2272 
2273  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file '%s'",
2274  m_libFileName.GetFullPath() );
2275 
2276  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2277 
2278  if( !reader.ReadLine() )
2279  THROW_IO_ERROR( _( "unexpected end of file" ) );
2280 
2281  const char* line = reader.Line();
2282 
2283  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2284  {
2285  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2286  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2287  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2288  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2289  }
2290 
2291  m_versionMajor = parseInt( reader, line, &line );
2292 
2293  if( *line != '.' )
2294  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2295 
2296  line++;
2297 
2298  m_versionMinor = parseInt( reader, line, &line );
2299 
2300  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2301  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2302 
2303  // Check if this is a symbol library which is the same as a component library but without
2304  // any alias, documentation, footprint filters, etc.
2305  if( strCompare( "SYMBOL", line, &line ) )
2306  {
2307  // Symbol files add date and time stamp info to the header.
2309 
2311  }
2312  else
2313  {
2315  }
2316 
2317  while( reader.ReadLine() )
2318  {
2319  line = reader.Line();
2320 
2321  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2322  continue;
2323 
2324  // Headers where only supported in older library file formats.
2325  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2326  loadHeader( reader );
2327 
2328  if( strCompare( "DEF", line ) )
2329  {
2330  // Read one DEF/ENDDEF part entry from library:
2331  loadPart( reader );
2332 
2333  }
2334  }
2335 
2336  ++m_modHash;
2337 
2338  // Remember the file modification time of library file when the
2339  // cache snapshot was made, so that in a networked environment we will
2340  // reload the cache as needed.
2342 
2344  loadDocs();
2345 }
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 loadHeader(FILE_LINE_READER &aReader)
const wxChar traceSchLegacyPlugin[]
Flag to enable legacy schematic plugin debug output.
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 2631 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2633 {
2634  wxString newAlias;
2635  const char* line = aReader.Line();
2636 
2637  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2638 
2639  // Parse the ALIAS list.
2640  wxString alias;
2641  parseUnquotedString( alias, aReader, line, &line );
2642 
2643  while( !alias.IsEmpty() )
2644  {
2645  newAlias = alias;
2646  checkForDuplicates( newAlias );
2647  aPart->AddAlias( newAlias );
2648  alias.clear();
2649  parseUnquotedString( alias, aReader, line, &line, true );
2650  }
2651 }
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 2888 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().

2890 {
2891  const char* line = aReader.Line();
2892 
2893  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
2894 
2895  std::unique_ptr< LIB_ARC > arc( new LIB_ARC( aPart.get() ) );
2896 
2897  wxPoint center;
2898 
2899  center.x = parseInt( aReader, line, &line );
2900  center.y = parseInt( aReader, line, &line );
2901 
2902  arc->SetPosition( center );
2903  arc->SetRadius( parseInt( aReader, line, &line ) );
2904 
2905  int angle1 = parseInt( aReader, line, &line );
2906  int angle2 = parseInt( aReader, line, &line );
2907 
2908  NORMALIZE_ANGLE_POS( angle1 );
2909  NORMALIZE_ANGLE_POS( angle2 );
2910  arc->SetFirstRadiusAngle( angle1 );
2911  arc->SetSecondRadiusAngle( angle2 );
2912 
2913  arc->SetUnit( parseInt( aReader, line, &line ) );
2914  arc->SetConvert( parseInt( aReader, line, &line ) );
2915  arc->SetWidth( parseInt( aReader, line, &line ) );
2916 
2917  // Old libraries (version <= 2.2) do not have always this FILL MODE param
2918  // when fill mode is no fill (default mode).
2919  if( *line != 0 )
2920  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
2921 
2922  // Actual Coordinates of arc ends are read from file
2923  if( *line != 0 )
2924  {
2925  wxPoint arcStart, arcEnd;
2926 
2927  arcStart.x = parseInt( aReader, line, &line );
2928  arcStart.y = parseInt( aReader, line, &line );
2929  arcEnd.x = parseInt( aReader, line, &line );
2930  arcEnd.y = parseInt( aReader, line, &line );
2931 
2932  arc->SetStart( arcStart );
2933  arc->SetEnd( arcEnd );
2934  }
2935  else
2936  {
2937  // Actual Coordinates of arc ends are not read from file
2938  // (old library), calculate them
2939  wxPoint arcStart( arc->GetRadius(), 0 );
2940  wxPoint arcEnd( arc->GetRadius(), 0 );
2941 
2942  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
2943  arcStart += arc->GetPosition();
2944  arc->SetStart( arcStart );
2945  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
2946  arcEnd += arc->GetPosition();
2947  arc->SetEnd( arcEnd );
2948  }
2949 
2950  return arc.release();
2951 }
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:317
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 3337 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3339 {
3340  const char* line = aReader.Line();
3341 
3342  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3343 
3344  std::unique_ptr< LIB_BEZIER > bezier( new LIB_BEZIER( aPart.get() ) );
3345 
3346  int points = parseInt( aReader, line, &line );
3347  bezier->SetUnit( parseInt( aReader, line, &line ) );
3348  bezier->SetConvert( parseInt( aReader, line, &line ) );
3349  bezier->SetWidth( parseInt( aReader, line, &line ) );
3350 
3351  wxPoint pt;
3352 
3353  for( int i = 0; i < points; i++ )
3354  {
3355  pt.x = parseInt( aReader, line, &line );
3356  pt.y = parseInt( aReader, line, &line );
3357  bezier->AddPoint( pt );
3358  }
3359 
3360  if( *line != 0 )
3361  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3362 
3363  return bezier.release();
3364 }
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)
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 2954 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

2956 {
2957  const char* line = aReader.Line();
2958 
2959  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
2960 
2961  std::unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
2962 
2963  wxPoint center;
2964 
2965  center.x = parseInt( aReader, line, &line );
2966  center.y = parseInt( aReader, line, &line );
2967 
2968  circle->SetPosition( center );
2969  circle->SetRadius( parseInt( aReader, line, &line ) );
2970  circle->SetUnit( parseInt( aReader, line, &line ) );
2971  circle->SetConvert( parseInt( aReader, line, &line ) );
2972  circle->SetWidth( parseInt( aReader, line, &line ) );
2973 
2974  if( *line != 0 )
2975  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
2976 
2977  return circle.release();
2978 }
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 2348 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(), and THROW_IO_ERROR.

Referenced by Load().

2349 {
2350  const char* line;
2351  wxString text;
2352  wxString aliasName;
2353  wxFileName fn = m_libFileName;
2354  LIB_ALIAS* alias = NULL;;
2355 
2356  fn.SetExt( DOC_EXT );
2357 
2358  // Not all libraries will have a document file.
2359  if( !fn.FileExists() )
2360  return;
2361 
2362  if( !fn.IsFileReadable() )
2363  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2364  "document file '%s'" ), fn.GetFullPath() ) );
2365 
2366  FILE_LINE_READER reader( fn.GetFullPath() );
2367 
2368  line = reader.ReadLine();
2369 
2370  if( !line )
2371  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2372 
2373  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2374  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2375  reader, line );
2376 
2377  while( reader.ReadLine() )
2378  {
2379  line = reader.Line();
2380 
2381  if( *line == '#' ) // Comment line.
2382  continue;
2383 
2384  if( !strCompare( "$CMP", line, &line ) != 0 )
2385  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2386 
2387  parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
2388 
2389  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2390 
2391  if( it == m_aliases.end() )
2392  wxLogWarning( "Alias '%s' not found in library:\n\n"
2393  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2394  reader.LineNumber(), (int) (line - reader.Line() ) );
2395  else
2396  alias = it->second;
2397 
2398  // Read the curent alias associated doc.
2399  // if the alias does not exist, just skip the description
2400  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2401  while( reader.ReadLine() )
2402  {
2403  line = reader.Line();
2404 
2405  if( !line )
2406  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2407 
2408  if( strCompare( "$ENDCMP", line, &line ) )
2409  break;
2410 
2411  text = FROM_UTF8( line + 2 );
2412  text = text.Trim();
2413 
2414  switch( line[0] )
2415  {
2416  case 'D':
2417  if( alias )
2418  alias->SetDescription( text );
2419  break;
2420 
2421  case 'K':
2422  if( alias )
2423  alias->SetKeyWords( text );
2424  break;
2425 
2426  case 'F':
2427  if( alias )
2428  alias->SetDocFileName( text );
2429  break;
2430 
2431  case '#':
2432  break;
2433 
2434  default:
2435  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2436  }
2437  }
2438  }
2439 }
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 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 2800 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().

2802 {
2803  const char* line = aReader.Line();
2804 
2805  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
2806 
2807  line = aReader.ReadLine();
2808 
2809  while( line )
2810  {
2811  if( strCompare( "ENDDRAW", line, &line ) )
2812  return;
2813 
2814  switch( line[0] )
2815  {
2816  case 'A': // Arc
2817  aPart->AddDrawItem( loadArc( aPart, aReader ) );
2818  break;
2819 
2820  case 'C': // Circle
2821  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
2822  break;
2823 
2824  case 'T': // Text
2825  aPart->AddDrawItem( loadText( aPart, aReader ) );
2826  break;
2827 
2828  case 'S': // Square
2829  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
2830  break;
2831 
2832  case 'X': // Pin Description
2833  aPart->AddDrawItem( loadPin( aPart, aReader ) );
2834  break;
2835 
2836  case 'P': // Polyline
2837  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
2838  break;
2839 
2840  case 'B': // Bezier Curves
2841  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
2842  break;
2843 
2844  case '#': // Comment
2845  case '\n': // Empty line
2846  case '\r':
2847  case 0:
2848  break;
2849 
2850  default:
2851  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
2852  }
2853 
2854  line = aReader.ReadLine();
2855  }
2856 
2857  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
2858 }
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 2654 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().

2656 {
2657  const char* line = aReader.Line();
2658 
2659  wxCHECK_RET( *line == 'F', "Invalid field line" );
2660 
2661  int id;
2662 
2663  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2664  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2665 
2666  std::unique_ptr< LIB_FIELD > field( new LIB_FIELD( aPart.get(), id ) );
2667 
2668  // Skip to the first double quote.
2669  while( *line != '"' && *line != 0 )
2670  line++;
2671 
2672  if( *line == 0 )
2673  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2674 
2675  wxString text;
2676  parseQuotedString( text, aReader, line, &line, true );
2677 
2678  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2679  // not save like this.
2680  if( text.size() == 1 && text[0] == '~' )
2681  text.clear();
2682 
2683  field->m_Text = text;
2684 
2685  wxPoint pos;
2686 
2687  pos.x = parseInt( aReader, line, &line );
2688  pos.y = parseInt( aReader, line, &line );
2689  field->SetPosition( pos );
2690 
2691  wxSize textSize;
2692 
2693  textSize.x = textSize.y = parseInt( aReader, line, &line );
2694  field->SetTextSize( textSize );
2695 
2696  char textOrient = parseChar( aReader, line, &line );
2697 
2698  if( textOrient == 'H' )
2699  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2700  else if( textOrient == 'V' )
2701  field->SetTextAngle( TEXT_ANGLE_VERT );
2702  else
2703  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
2704 
2705  char textVisible = parseChar( aReader, line, &line );
2706 
2707  if( textVisible == 'V' )
2708  field->SetVisible( true );
2709  else if ( textVisible == 'I' )
2710  field->SetVisible( false );
2711  else
2712  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
2713 
2714  // It may be technically correct to use the library version to determine if the field text
2715  // attributes are present. If anyone knows if that is valid and what version that would be,
2716  // please change this to test the library version rather than an EOL or the quoted string
2717  // of the field name.
2718  if( *line != 0 && *line != '"' )
2719  {
2720  char textHJustify = parseChar( aReader, line, &line );
2721 
2722  if( textHJustify == 'C' )
2723  field->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2724  else if( textHJustify == 'L' )
2725  field->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2726  else if( textHJustify == 'R' )
2727  field->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2728  else
2729  SCH_PARSE_ERROR( "invalid field text horizontal justification parameter",
2730  aReader, line );
2731 
2732  wxString attributes;
2733 
2734  parseUnquotedString( attributes, aReader, line, &line );
2735 
2736  if( !(attributes.size() == 3 || attributes.size() == 1 ) )
2737  SCH_PARSE_ERROR( "invalid field text attributes size",
2738  aReader, line );
2739 
2740  if( attributes[0] == 'C' )
2741  field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2742  else if( attributes[0] == 'B' )
2743  field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2744  else if( attributes[0] == 'T' )
2745  field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2746  else
2747  SCH_PARSE_ERROR( "invalid field text vertical justification parameter",
2748  aReader, line );
2749 
2750  if( attributes.size() == 3 )
2751  {
2752  if( attributes[1] == 'I' ) // Italic
2753  field->SetItalic( true );
2754  else if( attributes[1] != 'N' ) // No italics is default, check for error.
2755  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
2756 
2757  if ( attributes[2] == 'B' ) // Bold
2758  field->SetBold( true );
2759  else if( attributes[2] != 'N' ) // No bold is default, check for error.
2760  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
2761  }
2762  }
2763 
2764  // Fields in RAM must always have names.
2765  if( (unsigned) id < MANDATORY_FIELDS )
2766  {
2767  // Fields in RAM must always have names, because we are trying to get
2768  // less dependent on field ids and more dependent on names.
2769  // Plus assumptions are made in the field editors.
2770  field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
2771 
2772  LIB_FIELD* fixedField = aPart->GetField( field->GetId() );
2773 
2774  // this will fire only if somebody broke a constructor or editor.
2775  // MANDATORY_FIELDS are always present in ram resident components, no
2776  // exceptions, and they always have their names set, even fixed fields.
2777  wxASSERT( fixedField );
2778 
2779  *fixedField = *field;
2780 
2781  // Ensure the VALUE field = the part name (can be not the case
2782  // with malformed libraries: edited by hand, or converted from other tools)
2783  if( fixedField->GetId() == VALUE )
2784  fixedField->m_Text = aPart->GetName();
2785  }
2786  else
2787  {
2788  wxString name;
2789 
2790  parseQuotedString( name, aReader, line, &line, true ); // Optional.
2791 
2792  if( !name.IsEmpty() )
2793  field->m_name = name;
2794 
2795  aPart->AddDrawItem( field.release() ); // LIB_FIELD* is now owned by the LIB_PART.
2796  }
2797 }
#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:346
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:133
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 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.
const char * name
#define VALUE
void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3367 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

3369 {
3370  const char* line = aReader.Line();
3371 
3372  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3373 
3374  line = aReader.ReadLine();
3375 
3376  while( line )
3377  {
3378  if( strCompare( "$ENDFPLIST", line, &line ) )
3379  return;
3380 
3381  wxString footprint;
3382 
3383  parseUnquotedString( footprint, aReader, line, &line );
3384  aPart->GetFootprints().Add( footprint );
3385  line = aReader.ReadLine();
3386  }
3387 
3388  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3389 }
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 2442 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

2443 {
2444  const char* line = aReader.Line();
2445 
2446  wxASSERT( strCompare( "$HEADER", line, &line ) );
2447 
2448  while( aReader.ReadLine() )
2449  {
2450  line = (char*) aReader;
2451 
2452  // The time stamp saved in old library files is not used or saved in the latest
2453  // library file version.
2454  if( strCompare( "TimeStamp", line, &line ) )
2455  continue;
2456  else if( strCompare( "$ENDHEADER", line, &line ) )
2457  return;
2458  }
2459 
2460  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2461 }
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 2464 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

2465 {
2466  const char* line = aReader.Line();
2467 
2468  wxCHECK( strCompare( "DEF", line, &line ), NULL );
2469 
2470  // Read DEF line:
2471  char yes_no = 0;
2472 
2473  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2474 
2475  wxString name, prefix;
2476 
2477  parseUnquotedString( name, aReader, line, &line ); // Part name.
2478  parseUnquotedString( prefix, aReader, line, &line ); // Prefix name
2479  parseInt( aReader, line, &line ); // NumOfPins, unused.
2480  part->SetPinNameOffset( parseInt( aReader, line, &line ) ); // Pin name offset.
2481  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2482 
2483  if( !( yes_no == 'Y' || yes_no == 'N') )
2484  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2485 
2486  part->SetShowPinNumbers( ( yes_no == 'N' ) ? false : true );
2487 
2488  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2489 
2490  if( !( yes_no == 'Y' || yes_no == 'N') )
2491  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2492 
2493  part->SetShowPinNames( ( yes_no == 'N' ) ? false : true ); // Show pin names.
2494 
2495  part->SetUnitCount( parseInt( aReader, line, &line ) ); // Number of units.
2496 
2497  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2498  if( part->GetUnitCount() < 1 )
2499  part->SetUnitCount( 1 );
2500 
2501  // Copy part name and prefix.
2502 
2503  // The root alias is added to the alias list by SetName() which is called by SetText().
2504  if( name.IsEmpty() )
2505  {
2506  part->SetName( "~" );
2507  }
2508  else if( name[0] != '~' )
2509  {
2510  part->SetName( name );
2511  }
2512  else
2513  {
2514  part->SetName( name.Right( name.Length() - 1 ) );
2515  part->GetValueField().SetVisible( false );
2516  }
2517 
2518  // There are some code paths in SetText() that do not set the root alias to the
2519  // alias list so add it here if it didn't get added by SetText().
2520  if( !part->HasAlias( part->GetName() ) )
2521  part->AddAlias( part->GetName() );
2522 
2523  LIB_FIELD& reference = part->GetReferenceField();
2524 
2525  if( prefix == "~" )
2526  {
2527  reference.Empty();
2528  reference.SetVisible( false );
2529  }
2530  else
2531  {
2532  reference.SetText( prefix );
2533  }
2534 
2535  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2536  // The was no concept of interchangeable multiple unit symbols.
2538  {
2539  // Nothing needs to be set since the default setting for symbols with multiple
2540  // units were never interchangeable. Just parse the 0 an move on.
2541  parseInt( aReader, line, &line );
2542  }
2543  else
2544  {
2545  char locked = parseChar( aReader, line, &line );
2546 
2547  if( locked == 'L' )
2548  part->LockUnits( true );
2549  else if( locked == 'F' || locked == '0' )
2550  part->LockUnits( false );
2551  else
2552  SCH_PARSE_ERROR( "expected L, F, or 0", aReader, line );
2553  }
2554 
2555 
2556  // There is the optional power component flag.
2557  if( *line )
2558  {
2559  char power = parseChar( aReader, line, &line );
2560 
2561  if( power == 'P' )
2562  part->SetPower();
2563  else if( power == 'N' )
2564  part->SetNormal();
2565  else
2566  SCH_PARSE_ERROR( "expected P or N", aReader, line );
2567  }
2568 
2569  line = aReader.ReadLine();
2570 
2571  // Read lines until "ENDDEF" is found.
2572  while( line )
2573  {
2574  if( *line == '#' ) // Comment
2575  ;
2576  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2577  continue;
2578  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2579  loadAliases( part, aReader );
2580  else if( *line == 'F' ) // Fields
2581  loadField( part, aReader );
2582  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2583  loadDrawEntries( part, aReader );
2584  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2585  loadFootprintFilters( part, aReader );
2586  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2587  {
2588  // Now all is good, Add the root alias to the cache alias list.
2589  m_aliases[ part->GetName() ] = part->GetAlias( part->GetName() );
2590 
2591  // Add aliases when exist
2592  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2593  m_aliases[ part->GetAlias( ii )->GetName() ] = part->GetAlias( ii );
2594 
2595  return part.release();
2596  }
2597 
2598  line = aReader.ReadLine();
2599  }
2600 
2601  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2602 }
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:175
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
void loadAliases(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:504
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:231
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)
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...
const char * name
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 3120 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), name, parseChar(), parseInt(), parseUnquotedString(), 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, SCH_PARSE_ERROR, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3122 {
3123  const char* line = aReader.Line();
3124 
3125  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3126 
3127  std::unique_ptr< LIB_PIN > pin( new LIB_PIN( aPart.get() ) );
3128 
3129  wxString name, number;
3130 
3131  parseUnquotedString( name, aReader, line, &line );
3132  parseUnquotedString( number, aReader, line, &line );
3133 
3134  pin->SetName( name, false );
3135  pin->SetNumber( number );
3136 
3137  wxPoint pos;
3138 
3139  pos.x = parseInt( aReader, line, &line );
3140  pos.y = parseInt( aReader, line, &line );
3141  pin->SetPosition( pos );
3142  pin->SetLength( parseInt( aReader, line, &line ), false );
3143  pin->SetOrientation( parseChar( aReader, line, &line ), false );
3144  pin->SetNumberTextSize( parseInt( aReader, line, &line ), false );
3145  pin->SetNameTextSize( parseInt( aReader, line, &line ), false );
3146  pin->SetUnit( parseInt( aReader, line, &line ) );
3147  pin->SetConvert( parseInt( aReader, line, &line ) );
3148 
3149  char type = parseChar( aReader, line, &line );
3150 
3151  wxString attributes;
3152 
3153  // Optional
3154  parseUnquotedString( attributes, aReader, line, &line, true );
3155 
3156  switch( type )
3157  {
3158  case 'I':
3159  pin->SetType( PIN_INPUT, false );
3160  break;
3161 
3162  case 'O':
3163  pin->SetType( PIN_OUTPUT, false );
3164  break;
3165 
3166  case 'B':
3167  pin->SetType( PIN_BIDI, false );
3168  break;
3169 
3170  case 'T':
3171  pin->SetType( PIN_TRISTATE, false );
3172  break;
3173 
3174  case 'P':
3175  pin->SetType( PIN_PASSIVE, false );
3176  break;
3177 
3178  case 'U':
3179  pin->SetType( PIN_UNSPECIFIED, false );
3180  break;
3181 
3182  case 'W':
3183  pin->SetType( PIN_POWER_IN, false );
3184  break;
3185 
3186  case 'w':
3187  pin->SetType( PIN_POWER_OUT, false );
3188  break;
3189 
3190  case 'C':
3191  pin->SetType( PIN_OPENCOLLECTOR, false );
3192  break;
3193 
3194  case 'E':
3195  pin->SetType( PIN_OPENEMITTER, false );
3196  break;
3197 
3198  case 'N':
3199  pin->SetType( PIN_NC, false );
3200  break;
3201 
3202  default:
3203  SCH_PARSE_ERROR( "unknown pin type", aReader, line );
3204  }
3205 
3206  if( !attributes.IsEmpty() ) /* Special Symbol defined */
3207  {
3208  enum
3209  {
3210  INVERTED = 1 << 0,
3211  CLOCK = 1 << 1,
3212  LOWLEVEL_IN = 1 << 2,
3213  LOWLEVEL_OUT = 1 << 3,
3214  FALLING_EDGE = 1 << 4,
3215  NONLOGIC = 1 << 5
3216  };
3217 
3218  int flags = 0;
3219 
3220  for( int j = attributes.size(); j > 0; )
3221  {
3222  switch( attributes[--j].GetValue() )
3223  {
3224  case '~':
3225  break;
3226 
3227  case 'N':
3228  pin->SetVisible( false );
3229  break;
3230 
3231  case 'I':
3232  flags |= INVERTED;
3233  break;
3234 
3235  case 'C':
3236  flags |= CLOCK;
3237  break;
3238 
3239  case 'L':
3240  flags |= LOWLEVEL_IN;
3241  break;
3242 
3243  case 'V':
3244  flags |= LOWLEVEL_OUT;
3245  break;
3246 
3247  case 'F':
3248  flags |= FALLING_EDGE;
3249  break;
3250 
3251  case 'X':
3252  flags |= NONLOGIC;
3253  break;
3254 
3255  default:
3256  SCH_PARSE_ERROR( "unknown pin attribute", aReader, line );
3257  }
3258  }
3259 
3260  switch( flags )
3261  {
3262  case 0:
3263  pin->SetShape( PINSHAPE_LINE );
3264  break;
3265 
3266  case INVERTED:
3267  pin->SetShape( PINSHAPE_INVERTED );
3268  break;
3269 
3270  case CLOCK:
3271  pin->SetShape( PINSHAPE_CLOCK );
3272  break;
3273 
3274  case INVERTED | CLOCK:
3275  pin->SetShape( PINSHAPE_INVERTED_CLOCK );
3276  break;
3277 
3278  case LOWLEVEL_IN:
3279  pin->SetShape( PINSHAPE_INPUT_LOW );
3280  break;
3281 
3282  case LOWLEVEL_IN | CLOCK:
3283  pin->SetShape( PINSHAPE_CLOCK_LOW );
3284  break;
3285 
3286  case LOWLEVEL_OUT:
3287  pin->SetShape( PINSHAPE_OUTPUT_LOW );
3288  break;
3289 
3290  case FALLING_EDGE:
3291  pin->SetShape( PINSHAPE_FALLING_EDGE_CLOCK );
3292  break;
3293 
3294  case NONLOGIC:
3295  pin->SetShape( PINSHAPE_NONLOGIC );
3296  break;
3297 
3298  default:
3299  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3300  }
3301  }
3302 
3303  return pin.release();
3304 }
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 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...
const char * name
LIB_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3307 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3309 {
3310  const char* line = aReader.Line();
3311 
3312  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3313 
3314  std::unique_ptr< LIB_POLYLINE > polyLine( new LIB_POLYLINE( aPart.get() ) );
3315 
3316  int points = parseInt( aReader, line, &line );
3317  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3318  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3319  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3320 
3321  wxPoint pt;
3322 
3323  for( int i = 0; i < points; i++ )
3324  {
3325  pt.x = parseInt( aReader, line, &line );
3326  pt.y = parseInt( aReader, line, &line );
3327  polyLine->AddPoint( pt );
3328  }
3329 
3330  if( *line != 0 )
3331  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3332 
3333  return polyLine.release();
3334 }
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_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3088 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3090 {
3091  const char* line = aReader.Line();
3092 
3093  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3094 
3095  std::unique_ptr< LIB_RECTANGLE > rectangle( new LIB_RECTANGLE( aPart.get() ) );
3096 
3097  wxPoint pos;
3098 
3099  pos.x = parseInt( aReader, line, &line );
3100  pos.y = parseInt( aReader, line, &line );
3101  rectangle->SetPosition( pos );
3102 
3103  wxPoint end;
3104 
3105  end.x = parseInt( aReader, line, &line );
3106  end.y = parseInt( aReader, line, &line );
3107  rectangle->SetEnd( end );
3108 
3109  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3110  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3111  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3112 
3113  if( *line != 0 )
3114  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3115 
3116  return rectangle.release();
3117 }
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 2981 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, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

2983 {
2984  const char* line = aReader.Line();
2985 
2986  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
2987 
2988  std::unique_ptr< LIB_TEXT > text( new LIB_TEXT( aPart.get() ) );
2989 
2990  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
2991 
2992  wxPoint center;
2993 
2994  center.x = parseInt( aReader, line, &line );
2995  center.y = parseInt( aReader, line, &line );
2996  text->SetPosition( center );
2997 
2998  wxSize size;
2999 
3000  size.x = size.y = parseInt( aReader, line, &line );
3001  text->SetTextSize( size );
3002  text->SetVisible( !parseInt( aReader, line, &line ) );
3003  text->SetUnit( parseInt( aReader, line, &line ) );
3004  text->SetConvert( parseInt( aReader, line, &line ) );
3005 
3006  wxString str;
3007 
3008  // If quoted string loading fails, load as not quoted string.
3009  if( *line == '"' )
3010  parseQuotedString( str, aReader, line, &line );
3011  else
3012  parseUnquotedString( str, aReader, line, &line );
3013 
3014  if( !str.IsEmpty() )
3015  {
3016  // convert two apostrophes back to double quote
3017  str.Replace( "''", "\"" );
3018  str.Replace( wxT( "~" ), wxT( " " ) );
3019  }
3020 
3021  text->SetText( str );
3022 
3023  // Here things are murky and not well defined. At some point it appears the format
3024  // was changed to add text properties. However rather than add the token to the end of
3025  // the text definition, it was added after the string and no mention if the file
3026  // verion was bumped or not so this code make break on very old component libraries.
3027  //
3028  // Update: apparently even in the latest version this can be different so added a test
3029  // for end of line before checking for the text properties.
3030  if( LIB_VERSION( m_versionMajor, m_versionMinor ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3031  {
3032  if( strCompare( "Italic", line, &line ) )
3033  text->SetItalic( true );
3034  else if( !strCompare( "Normal", line, &line ) )
3035  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'",
3036  aReader, line );
3037 
3038  if( parseInt( aReader, line, &line ) > 0 )
3039  text->SetBold( true );
3040 
3041  // Some old libaries version > 2.0 do not have these options for text justification:
3042  if( !is_eol( *line ) )
3043  {
3044  switch( parseChar( aReader, line, &line ) )
3045  {
3046  case 'L':
3047  text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
3048  break;
3049 
3050  case 'C':
3051  text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
3052  break;
3053 
3054  case 'R':
3055  text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
3056  break;
3057 
3058  default:
3059  SCH_PARSE_ERROR( "invalid horizontal text justication parameter, expected L, C, or R",
3060  aReader, line );
3061  }
3062 
3063  switch( parseChar( aReader, line, &line ) )
3064  {
3065  case 'T':
3066  text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
3067  break;
3068 
3069  case 'C':
3070  text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
3071  break;
3072 
3073  case 'B':
3074  text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
3075  break;
3076 
3077  default:
3078  SCH_PARSE_ERROR( "invalid vertical text justication parameter, expected T, C, or B",
3079  aReader, line );
3080  }
3081  }
3082  }
3083 
3084  return text.release();
3085 }
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
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 2861 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().

2863 {
2864  FILL_T mode;
2865 
2866  switch( parseChar( aReader, aLine, aOutput ) )
2867  {
2868  case 'F':
2869  mode = FILLED_SHAPE;
2870  break;
2871 
2872  case 'f':
2873  mode = FILLED_WITH_BG_BODYCOLOR;
2874  break;
2875 
2876  case 'N':
2877  mode = NO_FILL;
2878  break;
2879 
2880  default:
2881  SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
2882  }
2883 
2884  return mode;
2885 }
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:70
LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

Definition at line 2199 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().

2200 {
2201  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2202 
2203  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2204 
2205  if( it == m_aliases.end() )
2206  return NULL;
2207 
2208  // If the entry pointer doesn't match the name it is mapped to in the library, we
2209  // have done something terribly wrong.
2210  wxCHECK_MSG( *it->second == aAlias, NULL,
2211  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2212  "> from library cache <" + m_libFileName.GetName() + ">." );
2213 
2214  LIB_ALIAS* alias = aAlias;
2215  LIB_PART* part = alias->GetPart();
2216 
2217  alias = part->RemoveAlias( alias );
2218 
2219  if( !alias )
2220  {
2221  delete part;
2222 
2223  if( m_aliases.size() > 1 )
2224  {
2225  LIB_ALIAS_MAP::iterator next = it;
2226  next++;
2227 
2228  if( next == m_aliases.end() )
2229  next = m_aliases.begin();
2230 
2231  alias = next->second;
2232  }
2233  }
2234 
2235  m_aliases.erase( it );
2236  m_isModified = true;
2237  ++m_modHash;
2238  return alias;
2239 }
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 3392 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 SCH_LEGACY_PLUGIN::CreateSymbolLib(), SCH_LEGACY_PLUGIN::DeleteAlias(), SCH_LEGACY_PLUGIN::DeleteSymbol(), SCH_LEGACY_PLUGIN::SaveLibrary(), and SCH_LEGACY_PLUGIN::SaveSymbol().

3393 {
3394  if( !m_isModified )
3395  return;
3396 
3397  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( m_libFileName.GetFullPath() ) );
3398  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3399  formatter->Print( 0, "#encoding utf-8\n");
3400 
3401  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3402  {
3403  if( !it->second->IsRoot() )
3404  continue;
3405 
3406  saveSymbol( it->second->GetPart(), formatter );
3407  }
3408 
3409  formatter->Print( 0, "#\n#End Library\n" );
3410  formatter.reset();
3411 
3412  m_fileModTime = m_libFileName.GetModificationTime();
3413  m_isModified = false;
3414 
3415  if( aSaveDocFile )
3416  saveDocFile();
3417 }
#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 3593 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().

3595 {
3596  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3597 
3598  int x1 = aArc->GetFirstRadiusAngle();
3599 
3600  if( x1 > 1800 )
3601  x1 -= 3600;
3602 
3603  int x2 = aArc->GetSecondRadiusAngle();
3604 
3605  if( x2 > 1800 )
3606  x2 -= 3600;
3607 
3608  aFormatter->Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3609  aArc->GetPosition().x, aArc->GetPosition().y,
3610  aArc->GetRadius(), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3611  aArc->GetWidth(), fill_tab[aArc->GetFillMode()],
3612  aArc->GetStart().x, aArc->GetStart().y,
3613  aArc->GetEnd().x, aArc->GetEnd().y );
3614 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
FILL_T GetFillMode() const
int GetSecondRadiusAngle() const
Definition: lib_arc.h:141
wxPoint GetStart() const
Definition: lib_arc.h:143
int GetUnit() const
int GetFirstRadiusAngle() const
Definition: lib_arc.h:137
wxPoint GetEnd() const
Definition: lib_arc.h:147
int GetRadius() const
Definition: lib_arc.h:133
int GetWidth() const override
Return the width of the draw item.
Definition: lib_arc.h:127
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_arc.h:116
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveBezier ( LIB_BEZIER aBezier,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3617 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3619 {
3620  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3621 
3622  aFormatter->Print( 0, "B %lu %d %d %d", (unsigned long)aBezier->GetCornerCount(),
3623  aBezier->GetUnit(), aBezier->GetConvert(), aBezier->GetWidth() );
3624 
3625  for( const auto& pt : aBezier->GetPoints() )
3626  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3627 
3628  aFormatter->Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3629 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:71
int GetWidth() const override
Return the width of the draw item.
Definition: lib_bezier.h:97
unsigned GetCornerCount() const
Definition: lib_bezier.h:69
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 3632 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().

3634 {
3635  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3636 
3637  aFormatter->Print( 0, "C %d %d %d %d %d %d %c\n",
3638  aCircle->GetPosition().x, aCircle->GetPosition().y,
3639  aCircle->GetRadius(), aCircle->GetUnit(), aCircle->GetConvert(),
3640  aCircle->GetWidth(), fill_tab[aCircle->GetFillMode()] );
3641 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
FILL_T GetFillMode() const
int GetUnit() const
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_circle.h:82
int GetWidth() const override
Return the width of the draw item.
Definition: lib_circle.h:93
int GetRadius() const
Definition: lib_circle.h:99
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 3889 of file sch_legacy_plugin.cpp.

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

Referenced by Save().

3890 {
3891  wxFileName fileName = m_libFileName;
3892 
3893  fileName.SetExt( DOC_EXT );
3894  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
3895 
3896  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
3897 
3898  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3899  {
3900  wxString description = it->second->GetDescription();
3901  wxString keyWords = it->second->GetKeyWords();
3902  wxString docFileName = it->second->GetDocFileName();
3903 
3904  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
3905  continue;
3906 
3907  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
3908 
3909  if( !description.IsEmpty() )
3910  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
3911 
3912  if( !keyWords.IsEmpty() )
3913  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
3914 
3915  if( !docFileName.IsEmpty() )
3916  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
3917 
3918  formatter.Print( 0, "$ENDCMP\n" );
3919  }
3920 
3921  formatter.Print( 0, "#\n#End Doc Library\n" );
3922 }
#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 3644 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 saveSymbol().

3646 {
3647  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3648 
3649  int hjustify, vjustify;
3650  int id = aField->GetId();
3651  wxString text = aField->m_Text;
3652 
3653  hjustify = 'C';
3654 
3655  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3656  hjustify = 'L';
3657  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3658  hjustify = 'R';
3659 
3660  vjustify = 'C';
3661 
3662  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3663  vjustify = 'B';
3664  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3665  vjustify = 'T';
3666 
3667  aFormatter->Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3668  id,
3669  EscapedUTF8( text ).c_str(), // wraps in quotes
3670  aField->GetTextPos().x, aField->GetTextPos().y, aField->GetTextWidth(),
3671  aField->GetTextAngle() == 0 ? 'H' : 'V',
3672  aField->IsVisible() ? 'V' : 'I',
3673  hjustify, vjustify,
3674  aField->IsItalic() ? 'I' : 'N',
3675  aField->IsBold() ? 'B' : 'N' );
3676 
3677  /* Save field name, if necessary
3678  * Field name is saved only if it is not the default name.
3679  * Just because default name depends on the language and can change from
3680  * a country to an other
3681  */
3682  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3683 
3684  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3685  aFormatter->Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3686 
3687  aFormatter->Print( 0, "\n" );
3688 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
wxString m_Text
Definition: eda_text.h:346
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
bool IsItalic() const
Definition: eda_text.h:170
int GetTextWidth() const
Definition: eda_text.h:218
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:190
bool IsBold() const
Definition: eda_text.h:173
double GetTextAngle() const
Definition: eda_text.h:164
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:133
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
bool IsVisible() const
Definition: lib_field.h:159
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 3691 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().

3693 {
3694  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3695 
3696  int Etype;
3697 
3698  switch( aPin->GetType() )
3699  {
3700  default:
3701  case PIN_INPUT:
3702  Etype = 'I';
3703  break;
3704 
3705  case PIN_OUTPUT:
3706  Etype = 'O';
3707  break;
3708 
3709  case PIN_BIDI:
3710  Etype = 'B';
3711  break;
3712 
3713  case PIN_TRISTATE:
3714  Etype = 'T';
3715  break;
3716 
3717  case PIN_PASSIVE:
3718  Etype = 'P';
3719  break;
3720 
3721  case PIN_UNSPECIFIED:
3722  Etype = 'U';
3723  break;
3724 
3725  case PIN_POWER_IN:
3726  Etype = 'W';
3727  break;
3728 
3729  case PIN_POWER_OUT:
3730  Etype = 'w';
3731  break;
3732 
3733  case PIN_OPENCOLLECTOR:
3734  Etype = 'C';
3735  break;
3736 
3737  case PIN_OPENEMITTER:
3738  Etype = 'E';
3739  break;
3740 
3741  case PIN_NC:
3742  Etype = 'N';
3743  break;
3744  }
3745 
3746  if( !aPin->GetName().IsEmpty() )
3747  aFormatter->Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
3748  else
3749  aFormatter->Print( 0, "X ~" );
3750 
3751  aFormatter->Print( 0, " %s %d %d %d %c %d %d %d %d %c",
3752  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
3753  aPin->GetPosition().x, aPin->GetPosition().y,
3754  (int) aPin->GetLength(), (int) aPin->GetOrientation(),
3755  aPin->GetNumberTextSize(), aPin->GetNameTextSize(),
3756  aPin->GetUnit(), aPin->GetConvert(), Etype );
3757 
3758  if( aPin->GetShape() || !aPin->IsVisible() )
3759  aFormatter->Print( 0, " " );
3760 
3761  if( !aPin->IsVisible() )
3762  aFormatter->Print( 0, "N" );
3763 
3764  switch( aPin->GetShape() )
3765  {
3766  case PINSHAPE_LINE:
3767  break;
3768 
3769  case PINSHAPE_INVERTED:
3770  aFormatter->Print( 0, "I" );
3771  break;
3772 
3773  case PINSHAPE_CLOCK:
3774  aFormatter->Print( 0, "C" );
3775  break;
3776 
3778  aFormatter->Print( 0, "IC" );
3779  break;
3780 
3781  case PINSHAPE_INPUT_LOW:
3782  aFormatter->Print( 0, "L" );
3783  break;
3784 
3785  case PINSHAPE_CLOCK_LOW:
3786  aFormatter->Print( 0, "CL" );
3787  break;
3788 
3789  case PINSHAPE_OUTPUT_LOW:
3790  aFormatter->Print( 0, "V" );
3791  break;
3792 
3794  aFormatter->Print( 0, "F" );
3795  break;
3796 
3797  case PINSHAPE_NONLOGIC:
3798  aFormatter->Print( 0, "X" );
3799  break;
3800 
3801  default:
3802  assert( !"Invalid pin shape" );
3803  }
3804 
3805  aFormatter->Print( 0, "\n" );
3806 
3807  aPin->ClearFlags( IS_CHANGED );
3808 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
int GetUnit() const
int GetNameTextSize() const
Definition: lib_pin.h:181
int GetOrientation() const
Definition: lib_pin.h:210
int GetNumberTextSize() const
Definition: lib_pin.h:208
const wxString & GetNumber() const
Definition: lib_pin.h:183
const wxString & GetName() const
Definition: lib_pin.h:155
#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:123
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:240
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:349
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:450
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:281
int GetLength()
Definition: lib_pin.h:290
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:224
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::savePolyLine ( LIB_POLYLINE aPolyLine,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3811 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().

3813 {
3814  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
3815 
3816  int ccount = aPolyLine->GetCornerCount();
3817 
3818  aFormatter->Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
3819  aPolyLine->GetWidth() );
3820 
3821  for( const auto& pt : aPolyLine->GetPolyPoints() )
3822  {
3823  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3824  }
3825 
3826  aFormatter->Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
3827 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:63
unsigned GetCornerCount() const
Definition: lib_polyline.h:73
int GetWidth() const override
Return the width of the draw item.
Definition: lib_polyline.h:108
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 3830 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().

3832 {
3833  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
3834  "Invalid LIB_RECTANGLE object." );
3835 
3836  aFormatter->Print( 0, "S %d %d %d %d %d %d %d %c\n",
3837  aRectangle->GetPosition().x, aRectangle->GetPosition().y,
3838  aRectangle->GetEnd().x, aRectangle->GetEnd().y,
3839  aRectangle->GetUnit(), aRectangle->GetConvert(),
3840  aRectangle->GetWidth(), fill_tab[aRectangle->GetFillMode()] );
3841 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
FILL_T GetFillMode() const
int GetUnit() const
int GetWidth() const override
Return the width of the draw item.
Definition: lib_rectangle.h:97
wxPoint GetEnd() const
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_rectangle.h:86
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveSymbol ( LIB_PART aSymbol,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3420 of file sch_legacy_plugin.cpp.

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_PART::GetAliasCount(), LIB_PART::GetAliasNames(), LIB_PART::GetDateModified(), 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(), 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().

3422 {
3423  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
3424 
3425  LIB_FIELD& value = aSymbol->GetValueField();
3426 
3427  // First line: it s a comment (component name for readers)
3428  aFormatter->Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3429 
3430  // Save data
3431  aFormatter->Print( 0, "DEF" );
3432 
3433  if( value.IsVisible() )
3434  {
3435  aFormatter->Print( 0, " %s", TO_UTF8( value.GetText() ) );
3436  }
3437  else
3438  {
3439  aFormatter->Print( 0, " ~%s", TO_UTF8( value.GetText() ) );
3440  }
3441 
3442  LIB_FIELD& reference = aSymbol->GetReferenceField();
3443 
3444  if( !reference.GetText().IsEmpty() )
3445  {
3446  aFormatter->Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3447  }
3448  else
3449  {
3450  aFormatter->Print( 0, " ~" );
3451  }
3452 
3453  aFormatter->Print( 0, " %d %d %c %c %d %c %c\n",
3454  0, aSymbol->GetPinNameOffset(),
3455  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3456  aSymbol->ShowPinNames() ? 'Y' : 'N',
3457  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3458  aSymbol->IsPower() ? 'P' : 'N' );
3459 
3460  long dateModified = aSymbol->GetDateModified();
3461 
3462  if( dateModified != 0 )
3463  {
3464  int year, mon, day, hour, min, sec;
3465 
3466  sec = dateModified & 63;
3467  min = ( dateModified >> 6 ) & 63;
3468  hour = ( dateModified >> 12 ) & 31;
3469  day = ( dateModified >> 17 ) & 31;
3470  mon = ( dateModified >> 22 ) & 15;
3471  year = ( dateModified >> 26 ) + 1990;
3472 
3473  aFormatter->Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3474  }
3475 
3476  LIB_FIELDS fields;
3477  aSymbol->GetFields( fields );
3478 
3479  // Mandatory fields:
3480  // may have their own save policy so there is a separate loop for them.
3481  // Empty fields are saved, because the user may have set visibility,
3482  // size and orientation
3483  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3484  {
3485  saveField( &fields[i], aFormatter );
3486  }
3487 
3488  // User defined fields:
3489  // may have their own save policy so there is a separate loop for them.
3490 
3491  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3492 
3493  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3494  {
3495  // There is no need to save empty fields, i.e. no reason to preserve field
3496  // names now that fields names come in dynamically through the template
3497  // fieldnames.
3498  if( !fields[i].GetText().IsEmpty() )
3499  {
3500  fields[i].SetId( fieldId++ );
3501  saveField( &fields[i], aFormatter );
3502  }
3503  }
3504 
3505  // Save the alias list: a line starting by "ALIAS". The first alias is the root
3506  // and has the same name as the component. In the old library file format this
3507  // alias does not get added to the alias list.
3508  if( aSymbol->GetAliasCount() > 1 )
3509  {
3510  wxArrayString aliases = aSymbol->GetAliasNames();
3511 
3512  aFormatter->Print( 0, "ALIAS" );
3513 
3514  for( unsigned i = 1; i < aliases.size(); i++ )
3515  {
3516  aFormatter->Print( 0, " %s", TO_UTF8( aliases[i] ) );
3517  }
3518 
3519  aFormatter->Print( 0, "\n" );
3520  }
3521 
3522  wxArrayString footprints = aSymbol->GetFootprints();
3523 
3524  // Write the footprint filter list
3525  if( footprints.GetCount() != 0 )
3526  {
3527  aFormatter->Print( 0, "$FPLIST\n" );
3528 
3529  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3530  {
3531  aFormatter->Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3532  }
3533 
3534  aFormatter->Print( 0, "$ENDFPLIST\n" );
3535  }
3536 
3537  // Save graphics items (including pins)
3538  if( !aSymbol->GetDrawItems().empty() )
3539  {
3540  // Sort the draw items in order to editing a file editing by hand.
3541  aSymbol->GetDrawItems().sort();
3542 
3543  aFormatter->Print( 0, "DRAW\n" );
3544 
3545  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3546  {
3547  switch( item.Type() )
3548  {
3549  case LIB_FIELD_T: // Fields have already been saved above.
3550  continue;
3551 
3552  case LIB_ARC_T:
3553  saveArc( (LIB_ARC*) &item, aFormatter );
3554  break;
3555 
3556  case LIB_BEZIER_T:
3557  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3558  break;
3559 
3560 
3561  case LIB_CIRCLE_T:
3562  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3563  break;
3564 
3565  case LIB_PIN_T:
3566  savePin( (LIB_PIN* ) &item, aFormatter );
3567  break;
3568 
3569  case LIB_POLYLINE_T:
3570  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3571  break;
3572 
3573  case LIB_RECTANGLE_T:
3574  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3575  break;
3576 
3577  case LIB_TEXT_T:
3578  saveText( ( LIB_TEXT* ) &item, aFormatter );
3579  break;
3580 
3581  default:
3582  ;
3583  }
3584  }
3585 
3586  aFormatter->Print( 0, "ENDDRAW\n" );
3587  }
3588 
3589  aFormatter->Print( 0, "ENDDEF\n" );
3590 }
bool UnitsLocked() const
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
long GetDateModified() const
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:130
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
wxArrayString & GetFootprints()
int GetUnitCount() const
bool IsVisible() const
Definition: lib_field.h:159
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:252
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
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 3844 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 saveSymbol().

3846 {
3847  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
3848 
3849  wxString text = aText->GetText();
3850 
3851  if( text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
3852  {
3853  // convert double quote to similar-looking two apostrophes
3854  text.Replace( wxT( "\"" ), wxT( "''" ) );
3855  text = wxT( "\"" ) + text + wxT( "\"" );
3856  }
3857  else
3858  {
3859  // Spaces are not allowed in text because it is not double quoted:
3860  // changed to '~'
3861  text.Replace( wxT( " " ), wxT( "~" ) );
3862  }
3863 
3864  aFormatter->Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
3865  aText->GetTextPos().x, aText->GetTextPos().y,
3866  aText->GetTextWidth(), !aText->IsVisible(),
3867  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
3868 
3869  aFormatter->Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
3870 
3871  char hjustify = 'C';
3872 
3873  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3874  hjustify = 'L';
3875  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3876  hjustify = 'R';
3877 
3878  char vjustify = 'C';
3879 
3880  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3881  vjustify = 'B';
3882  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3883  vjustify = 'T';
3884 
3885  aFormatter->Print( 0, " %c %c\n", hjustify, vjustify );
3886 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
bool IsItalic() const
Definition: eda_text.h:170
int GetUnit() const
int GetTextWidth() const
Definition: eda_text.h:218
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
bool IsBold() const
Definition: eda_text.h:173
double GetTextAngle() const
Definition: eda_text.h:164
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
bool IsVisible() const
Definition: eda_text.h:176
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 556 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

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

Member Data Documentation

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 475 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 478 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

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

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

int SCH_LEGACY_PLUGIN_CACHE::m_modHash = 1
staticprivate

Definition at line 472 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteAlias(), GetModifyHash(), Load(), and removeAlias().

int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 479 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 480 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 523 of file sch_legacy_plugin.cpp.


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