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)
 
wxFileName GetRealFile () const
 
wxDateTime GetLibModificationTime ()
 
bool IsFile (const wxString &aFullPathAndFileName) const
 
bool IsFileChanged () const
 
void SetModified (bool aModified=true)
 
wxString GetLogicalName () const
 
void SetFileName (const wxString &aFileName)
 
wxString GetFileName () const
 

Private Member Functions

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

Private Attributes

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

Static Private Attributes

static int m_modHash = 1
 

Detailed Description

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

not placed into a header.

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

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

2207 {
2208  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2209  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2210  {
2211  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2212  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2213  LIB_PART* part = it->second->GetPart();
2214  LIB_ALIAS* alias = it->second;
2215  delete alias;
2216 
2217  // When the last alias of a part is destroyed, the part is no longer required and it
2218  // too is destroyed.
2219  if( part && part->GetAliasCount() == 0 )
2220  delete part;
2221  }
2222 
2223  m_aliases.clear();
2224 }
Part library alias object definition.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
size_t GetAliasCount() const
Define a library symbol object.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
wxString GetLogicalName() const

Member Function Documentation

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 2323 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

2324 {
2325  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2326  wxArrayString aliasNames = aPart->GetAliasNames();
2327 
2328  for( size_t i = 0; i < aliasNames.size(); i++ )
2329  {
2330  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2331 
2332  if( it != m_aliases.end() )
2333  removeAlias( it->second );
2334 
2335  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2336 
2337  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2338  aPart->GetName() +">." );
2339 
2340  m_aliases[ aliasNames[i] ] = alias;
2341  }
2342 
2343  m_isModified = true;
2344  ++m_modHash;
2345 }
Part library alias object definition.
Define a library symbol object.
LIB_ALIAS * removeAlias(LIB_ALIAS *aAlias)
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
const wxString & GetName() const
bool SCH_LEGACY_PLUGIN_CACHE::checkForDuplicates ( wxString &  aAliasName)
private

Definition at line 2774 of file sch_legacy_plugin.cpp.

References m_aliases.

Referenced by loadAliases().

2775 {
2776  wxCHECK_MSG( !aAliasName.IsEmpty(), false, "alias name cannot be empty" );
2777 
2778  // The alias name is not a duplicate so don't change it.
2779  if( m_aliases.find( aAliasName ) == m_aliases.end() )
2780  return false;
2781 
2782  int dupCounter = 1;
2783  wxString newAlias = aAliasName;
2784 
2785  // If the alias is already loaded, the library is broken. It may have been possible in
2786  // the past that this could happen so we assign a new alias name to prevent any conflicts
2787  // rather than throw an exception.
2788  while( m_aliases.find( newAlias ) != m_aliases.end() )
2789  {
2790  newAlias = aAliasName << dupCounter;
2791  dupCounter++;
2792  }
2793 
2794  aAliasName = newAlias;
2795 
2796  return true;
2797 }
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

Definition at line 4049 of file sch_legacy_plugin.cpp.

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

Referenced by DeleteSymbol(), and GetModifyHash().

4050 {
4051  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4052 
4053  if( it == m_aliases.end() )
4054  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4055  m_libFileName.GetFullName(), aAliasName ) );
4056 
4057  LIB_ALIAS* alias = it->second;
4058  LIB_PART* part = alias->GetPart();
4059 
4060  alias = part->RemoveAlias( alias );
4061 
4062  if( !alias )
4063  {
4064  delete part;
4065 
4066  if( m_aliases.size() > 1 )
4067  {
4068  LIB_ALIAS_MAP::iterator next = it;
4069  next++;
4070 
4071  if( next == m_aliases.end() )
4072  next = m_aliases.begin();
4073 
4074  alias = next->second;
4075  }
4076  }
4077 
4078  m_aliases.erase( it );
4079  ++m_modHash;
4080  m_isModified = true;
4081 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol object.
#define THROW_IO_ERROR(msg)
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
void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aAliasName)

Definition at line 4084 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

4085 {
4086  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4087 
4088  if( it == m_aliases.end() )
4089  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4090  m_libFileName.GetFullName(), aAliasName ) );
4091 
4092  LIB_ALIAS* alias = it->second;
4093  LIB_PART* part = alias->GetPart();
4094 
4095  wxArrayString aliasNames = part->GetAliasNames();
4096 
4097  // Deleting all of the aliases deletes the symbol from the library.
4098  for( size_t i = 0; i < aliasNames.Count(); i++ )
4099  DeleteAlias( aliasNames[i] );
4100 }
Part library alias object definition.
void DeleteAlias(const wxString &aAliasName)
Define a library symbol object.
#define THROW_IO_ERROR(msg)
LIB_PART * GetPart() const
Get the shared LIB_PART.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 557 of file sch_legacy_plugin.cpp.

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

Definition at line 2251 of file sch_legacy_plugin.cpp.

References GetRealFile(), and m_isWritable.

Referenced by GetModifyHash(), and Load().

2252 {
2253  wxFileName fn = GetRealFile();
2254 
2255  // update the writable flag while we have a wxFileName, in a network this
2256  // is possibly quite dynamic anyway.
2257  m_isWritable = fn.IsFileWritable();
2258 
2259  return fn.GetModificationTime();
2260 }
wxFileName GetRealFile() const
wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 553 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

553 { return m_libFileName.GetName(); }
int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline
wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile ( ) const

Definition at line 2228 of file sch_legacy_plugin.cpp.

References m_libFileName, and TO_UTF8.

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

2229 {
2230  wxFileName fn( m_libFileName );
2231 
2232 #ifndef __WINDOWS__
2233  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2234  {
2235  char buffer[ PATH_MAX + 1 ];
2236  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2237 
2238  if( pathLen > 0 )
2239  {
2240  buffer[ pathLen ] = '\0';
2241  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2242  fn.Normalize();
2243  }
2244  }
2245 #endif
2246 
2247  return fn;
2248 }
#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 SCH_LEGACY_PLUGIN_CACHE::IsFile ( const wxString &  aFullPathAndFileName) const

Definition at line 2263 of file sch_legacy_plugin.cpp.

References m_fileName.

Referenced by GetModifyHash().

2264 {
2265  return m_fileName == aFullPathAndFileName;
2266 }
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2269 of file sch_legacy_plugin.cpp.

References GetRealFile(), and m_fileModTime.

Referenced by GetModifyHash().

2270 {
2271  wxFileName fn = GetRealFile();
2272 
2273  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2274  return fn.GetModificationTime() != m_fileModTime;
2275 
2276  return false;
2277 }
wxFileName GetRealFile() const
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 2348 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

2349 {
2350  if( !m_libFileName.FileExists() )
2351  {
2352  wxString msg = wxString::Format( _( "Library file \"%s\" not found.\n\n"
2353  "Use the Manage Symbol Libraries dialog to fix the "
2354  "path (or remove the library)." ),
2355  m_libFileName.GetFullPath() );
2356  KIDIALOG dlg( Pgm().App().GetTopWindow(), msg, KIDIALOG::KD_ERROR );
2357  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
2358  dlg.ShowModal();
2359  return;
2360  }
2361 
2362  wxCHECK_RET( m_libFileName.IsAbsolute(),
2363  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2364  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2365 
2366  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2367  m_libFileName.GetFullPath() );
2368 
2369  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2370 
2371  if( !reader.ReadLine() )
2372  THROW_IO_ERROR( _( "unexpected end of file" ) );
2373 
2374  const char* line = reader.Line();
2375 
2376  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2377  {
2378  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2379  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2380  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2381  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2382  }
2383 
2384  m_versionMajor = parseInt( reader, line, &line );
2385 
2386  if( *line != '.' )
2387  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2388 
2389  line++;
2390 
2391  m_versionMinor = parseInt( reader, line, &line );
2392 
2393  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2394  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2395 
2396  // Check if this is a symbol library which is the same as a component library but without
2397  // any alias, documentation, footprint filters, etc.
2398  if( strCompare( "SYMBOL", line, &line ) )
2399  {
2400  // Symbol files add date and time stamp info to the header.
2402 
2404  }
2405  else
2406  {
2408  }
2409 
2410  while( reader.ReadLine() )
2411  {
2412  line = reader.Line();
2413 
2414  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2415  continue;
2416 
2417  // Headers where only supported in older library file formats.
2418  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2419  loadHeader( reader );
2420 
2421  if( strCompare( "DEF", line ) )
2422  {
2423  // Read one DEF/ENDDEF part entry from library:
2424  loadPart( reader );
2425  }
2426  }
2427 
2428  ++m_modHash;
2429 
2430  // Remember the file modification time of library file when the
2431  // cache snapshot was made, so that in a networked environment we will
2432  // reload the cache as needed.
2434 
2436  loadDocs();
2437 }
Helper class to create more flexible dialogs, including &#39;do not show again&#39; checkbox handling...
Definition: confirm.h:44
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
void loadHeader(FILE_LINE_READER &aReader)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define THROW_IO_ERROR(msg)
#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...
void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2800 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2802 {
2803  wxString newAlias;
2804  const char* line = aReader.Line();
2805 
2806  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2807 
2808  wxString utf8Line = wxString::FromUTF8( line );
2809  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2810 
2811  // Parse the ALIAS list.
2812  while( tokens.HasMoreTokens() )
2813  {
2814  newAlias = tokens.GetNextToken();
2815  checkForDuplicates( newAlias );
2816  aPart->AddAlias( newAlias );
2817  }
2818 }
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 3038 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3040 {
3041  const char* line = aReader.Line();
3042 
3043  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
3044 
3045  LIB_ARC* arc = new LIB_ARC( aPart.get() );
3046 
3047  wxPoint center;
3048 
3049  center.x = parseInt( aReader, line, &line );
3050  center.y = parseInt( aReader, line, &line );
3051 
3052  arc->SetPosition( center );
3053  arc->SetRadius( parseInt( aReader, line, &line ) );
3054 
3055  int angle1 = parseInt( aReader, line, &line );
3056  int angle2 = parseInt( aReader, line, &line );
3057 
3058  NORMALIZE_ANGLE_POS( angle1 );
3059  NORMALIZE_ANGLE_POS( angle2 );
3060  arc->SetFirstRadiusAngle( angle1 );
3061  arc->SetSecondRadiusAngle( angle2 );
3062 
3063  arc->SetUnit( parseInt( aReader, line, &line ) );
3064  arc->SetConvert( parseInt( aReader, line, &line ) );
3065  arc->SetWidth( parseInt( aReader, line, &line ) );
3066 
3067  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3068  // when fill mode is no fill (default mode).
3069  if( *line != 0 )
3070  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3071 
3072  // Actual Coordinates of arc ends are read from file
3073  if( *line != 0 )
3074  {
3075  wxPoint arcStart, arcEnd;
3076 
3077  arcStart.x = parseInt( aReader, line, &line );
3078  arcStart.y = parseInt( aReader, line, &line );
3079  arcEnd.x = parseInt( aReader, line, &line );
3080  arcEnd.y = parseInt( aReader, line, &line );
3081 
3082  arc->SetStart( arcStart );
3083  arc->SetEnd( arcEnd );
3084  }
3085  else
3086  {
3087  // Actual Coordinates of arc ends are not read from file
3088  // (old library), calculate them
3089  wxPoint arcStart( arc->GetRadius(), 0 );
3090  wxPoint arcEnd( arc->GetRadius(), 0 );
3091 
3092  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3093  arcStart += arc->GetPosition();
3094  arc->SetStart( arcStart );
3095  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3096  arcEnd += arc->GetPosition();
3097  arc->SetEnd( arcEnd );
3098  }
3099 
3100  return arc;
3101 }
void SetPosition(const wxPoint &aPosition)
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 SetFirstRadiusAngle(int aAngle)
Definition: lib_arc.h:140
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:241
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_arc.h:134
void SetEnd(const wxPoint &aPoint)
Definition: lib_arc.h:154
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
int GetRadius() const
Definition: lib_arc.h:138
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFillMode)
void SetSecondRadiusAngle(int aAngle)
Definition: lib_arc.h:144
void SetConvert(int aConvert)
void SetUnit(int aUnit)
void SetRadius(int aRadius)
Definition: lib_arc.h:136
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetStart(const wxPoint &aPoint)
Definition: lib_arc.h:150
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_arc.h:121
LIB_BEZIER * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3466 of file sch_legacy_plugin.cpp.

References LIB_BEZIER::AddPoint(), bezier(), i, LINE_READER::Line(), parseFillMode(), parseInt(), LIB_BEZIER::Reserve(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetUnit(), LIB_BEZIER::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

3468 {
3469  const char* line = aReader.Line();
3470 
3471  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3472 
3473  LIB_BEZIER* bezier = new LIB_BEZIER( aPart.get() );
3474 
3475  int points = parseInt( aReader, line, &line );
3476  bezier->SetUnit( parseInt( aReader, line, &line ) );
3477  bezier->SetConvert( parseInt( aReader, line, &line ) );
3478  bezier->SetWidth( parseInt( aReader, line, &line ) );
3479 
3480  wxPoint pt;
3481  bezier->Reserve( points );
3482 
3483  for( int i = 0; i < points; i++ )
3484  {
3485  pt.x = parseInt( aReader, line, &line );
3486  pt.y = parseInt( aReader, line, &line );
3487  bezier->AddPoint( pt );
3488  }
3489 
3490  if( *line != 0 )
3491  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3492 
3493  return bezier;
3494 }
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
void Reserve(size_t aCount)
Definition: lib_bezier.h:66
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)
void SetFillMode(FILL_T aFillMode)
void SetConvert(int aConvert)
void SetUnit(int aUnit)
size_t i
Definition: json11.cpp:597
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_bezier.h:104
void AddPoint(const wxPoint &aPoint)
Definition: lib_bezier.h:67
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 3104 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3106 {
3107  const char* line = aReader.Line();
3108 
3109  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3110 
3111  LIB_CIRCLE* circle = new LIB_CIRCLE( aPart.get() );
3112 
3113  wxPoint center;
3114 
3115  center.x = parseInt( aReader, line, &line );
3116  center.y = parseInt( aReader, line, &line );
3117 
3118  circle->SetPosition( center );
3119  circle->SetRadius( parseInt( aReader, line, &line ) );
3120  circle->SetUnit( parseInt( aReader, line, &line ) );
3121  circle->SetConvert( parseInt( aReader, line, &line ) );
3122  circle->SetWidth( parseInt( aReader, line, &line ) );
3123 
3124  if( *line != 0 )
3125  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3126 
3127  return circle;
3128 }
void SetPosition(const wxPoint &aPosition)
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
void SetRadius(int aRadius)
Definition: lib_circle.h:101
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFillMode)
void SetConvert(int aConvert)
void SetUnit(int aUnit)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_circle.h:99
void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2440 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

2441 {
2442  const char* line;
2443  wxString text;
2444  wxString aliasName;
2445  wxFileName fn = m_libFileName;
2446  LIB_ALIAS* alias = NULL;;
2447 
2448  fn.SetExt( DOC_EXT );
2449 
2450  // Not all libraries will have a document file.
2451  if( !fn.FileExists() )
2452  return;
2453 
2454  if( !fn.IsFileReadable() )
2455  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2456  "document file \"%s\"" ), fn.GetFullPath() ) );
2457 
2458  FILE_LINE_READER reader( fn.GetFullPath() );
2459 
2460  line = reader.ReadLine();
2461 
2462  if( !line )
2463  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2464 
2465  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2466  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2467  reader, line );
2468 
2469  while( reader.ReadLine() )
2470  {
2471  line = reader.Line();
2472 
2473  if( *line == '#' ) // Comment line.
2474  continue;
2475 
2476  if( !strCompare( "$CMP", line, &line ) != 0 )
2477  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2478 
2479  aliasName = wxString::FromUTF8( line );
2480  aliasName.Trim();
2481  aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH );
2482 
2483  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2484 
2485  if( it == m_aliases.end() )
2486  wxLogWarning( "Alias '%s' not found in library:\n\n"
2487  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2488  reader.LineNumber(), (int) (line - reader.Line() ) );
2489  else
2490  alias = it->second;
2491 
2492  // Read the curent alias associated doc.
2493  // if the alias does not exist, just skip the description
2494  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2495  while( reader.ReadLine() )
2496  {
2497  line = reader.Line();
2498 
2499  if( !line )
2500  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2501 
2502  if( strCompare( "$ENDCMP", line, &line ) )
2503  break;
2504 
2505  text = FROM_UTF8( line + 2 );
2506  // Remove spaces at eol, and eol chars:
2507  text = text.Trim();
2508 
2509  switch( line[0] )
2510  {
2511  case 'D':
2512  if( alias )
2513  alias->SetDescription( text );
2514  break;
2515 
2516  case 'K':
2517  if( alias )
2518  alias->SetKeyWords( text );
2519  break;
2520 
2521  case 'F':
2522  if( alias )
2523  alias->SetDocFileName( text );
2524  break;
2525 
2526  case 0:
2527  case '\n':
2528  case '\r':
2529  case '#':
2530  // Empty line or commment
2531  break;
2532 
2533  default:
2534  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2535  }
2536  }
2537  }
2538 }
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
#define DOC_EXT
Definition: class_library.h:50
#define THROW_IO_ERROR(msg)
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...
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:352
void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

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

2966 {
2967  const char* line = aReader.Line();
2968 
2969  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
2970 
2971  line = aReader.ReadLine();
2972 
2973  while( line )
2974  {
2975  if( strCompare( "ENDDRAW", line, &line ) )
2976  return;
2977 
2978  switch( line[0] )
2979  {
2980  case 'A': // Arc
2981  aPart->AddDrawItem( loadArc( aPart, aReader ) );
2982  break;
2983 
2984  case 'C': // Circle
2985  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
2986  break;
2987 
2988  case 'T': // Text
2989  aPart->AddDrawItem( loadText( aPart, aReader ) );
2990  break;
2991 
2992  case 'S': // Square
2993  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
2994  break;
2995 
2996  case 'X': // Pin Description
2997  aPart->AddDrawItem( loadPin( aPart, aReader ) );
2998  break;
2999 
3000  case 'P': // Polyline
3001  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
3002  break;
3003 
3004  case 'B': // Bezier Curves
3005  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
3006  break;
3007 
3008  case '#': // Comment
3009  case '\n': // Empty line
3010  case '\r':
3011  case 0:
3012  break;
3013 
3014  default:
3015  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3016  }
3017 
3018  line = aReader.ReadLine();
3019  }
3020 
3021  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
3022 }
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 2821 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2823 {
2824  const char* line = aReader.Line();
2825 
2826  wxCHECK_RET( *line == 'F', "Invalid field line" );
2827 
2828  int id;
2829 
2830  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2831  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2832 
2833  LIB_FIELD* field;
2834 
2835  if( (unsigned) id < MANDATORY_FIELDS )
2836  {
2837  field = aPart->GetField( id );
2838 
2839  // this will fire only if somebody broke a constructor or editor.
2840  // MANDATORY_FIELDS are always present in ram resident components, no
2841  // exceptions, and they always have their names set, even fixed fields.
2842  wxASSERT( field );
2843  }
2844  else
2845  {
2846  field = new LIB_FIELD( aPart.get(), id );
2847  aPart->AddDrawItem( field );
2848  }
2849 
2850  // Skip to the first double quote.
2851  while( *line != '"' && *line != 0 )
2852  line++;
2853 
2854  if( *line == 0 )
2855  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2856 
2857  parseQuotedString( field->m_Text, aReader, line, &line, true );
2858 
2859  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2860  // not save like this.
2861  if( field->m_Text.size() == 1 && field->m_Text[0] == '~' )
2862  field->m_Text.clear();
2863 
2864  wxPoint pos;
2865 
2866  pos.x = parseInt( aReader, line, &line );
2867  pos.y = parseInt( aReader, line, &line );
2868  field->SetPosition( pos );
2869 
2870  wxSize textSize;
2871 
2872  textSize.x = textSize.y = parseInt( aReader, line, &line );
2873  field->SetTextSize( textSize );
2874 
2875  char textOrient = parseChar( aReader, line, &line );
2876 
2877  if( textOrient == 'H' )
2878  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2879  else if( textOrient == 'V' )
2880  field->SetTextAngle( TEXT_ANGLE_VERT );
2881  else
2882  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
2883 
2884  char textVisible = parseChar( aReader, line, &line );
2885 
2886  if( textVisible == 'V' )
2887  field->SetVisible( true );
2888  else if ( textVisible == 'I' )
2889  field->SetVisible( false );
2890  else
2891  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
2892 
2893  // It may be technically correct to use the library version to determine if the field text
2894  // attributes are present. If anyone knows if that is valid and what version that would be,
2895  // please change this to test the library version rather than an EOL or the quoted string
2896  // of the field name.
2897  if( *line != 0 && *line != '"' )
2898  {
2899  char textHJustify = parseChar( aReader, line, &line );
2900 
2901  if( textHJustify == 'C' )
2903  else if( textHJustify == 'L' )
2905  else if( textHJustify == 'R' )
2907  else
2908  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
2909 
2910  wxString attributes;
2911 
2912  parseUnquotedString( attributes, aReader, line, &line );
2913 
2914  size_t attrSize = attributes.size();
2915 
2916  if( !(attrSize == 3 || attrSize == 1 ) )
2917  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
2918 
2919  switch( (wxChar) attributes[0] )
2920  {
2921  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
2922  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
2923  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
2924  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
2925  }
2926 
2927  if( attrSize == 3 )
2928  {
2929  wxChar attr_1 = attributes[1];
2930  wxChar attr_2 = attributes[2];
2931 
2932  if( attr_1 == 'I' ) // Italic
2933  field->SetItalic( true );
2934  else if( attr_1 != 'N' ) // No italics is default, check for error.
2935  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
2936 
2937  if ( attr_2 == 'B' ) // Bold
2938  field->SetBold( true );
2939  else if( attr_2 != 'N' ) // No bold is default, check for error.
2940  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
2941  }
2942  }
2943 
2944  // Fields in RAM must always have names.
2945  if( (unsigned) id < MANDATORY_FIELDS )
2946  {
2947  // Fields in RAM must always have names, because we are trying to get
2948  // less dependent on field ids and more dependent on names.
2949  // Plus assumptions are made in the field editors.
2951 
2952  // Ensure the VALUE field = the part name (can be not the case
2953  // with malformed libraries: edited by hand, or converted from other tools)
2954  if( id == VALUE )
2955  field->m_Text = aPart->GetName();
2956  }
2957  else
2958  {
2959  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
2960  }
2961 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
#define TEXT_ANGLE_HORIZ
wxString m_Text
Definition: eda_text.h:374
void SetPosition(const wxPoint &aPosition)
#define TEXT_ANGLE_VERT
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.
void SetItalic(bool isItalic)
Definition: eda_text.h:182
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:188
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
#define VALUE
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 SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:207
#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.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void SetBold(bool aBold)
Definition: eda_text.h:185
void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3497 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

3499 {
3500  const char* line = aReader.Line();
3501 
3502  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3503 
3504  line = aReader.ReadLine();
3505 
3506  while( line )
3507  {
3508  if( strCompare( "$ENDFPLIST", line, &line ) )
3509  return;
3510 
3511  wxString footprint;
3512 
3513  parseUnquotedString( footprint, aReader, line, &line );
3514  aPart->GetFootprints().Add( footprint );
3515  line = aReader.ReadLine();
3516  }
3517 
3518  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3519 }
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 2541 of file sch_legacy_plugin.cpp.

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

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

2542 {
2543  const char* line = aReader.Line();
2544 
2545  wxASSERT( strCompare( "$HEADER", line, &line ) );
2546 
2547  while( aReader.ReadLine() )
2548  {
2549  line = (char*) aReader;
2550 
2551  // The time stamp saved in old library files is not used or saved in the latest
2552  // library file version.
2553  if( strCompare( "TimeStamp", line, &line ) )
2554  continue;
2555  else if( strCompare( "$ENDHEADER", line, &line ) )
2556  return;
2557  }
2558 
2559  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2560 }
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 2563 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

2564 {
2565  const char* line = aReader.Line();
2566 
2567  wxCHECK( strCompare( "DEF", line, &line ), NULL );
2568 
2569  long num;
2570  size_t pos = 4; // "DEF" plus the first space.
2571  wxString utf8Line = wxString::FromUTF8( line );
2572  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2573 
2574  if( tokens.CountTokens() < 8 )
2575  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2576 
2577  // Read DEF line:
2578  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2579 
2580  wxString name, prefix, tmp;
2581 
2582  name = tokens.GetNextToken();
2583  pos += name.size() + 1;
2584 
2585  prefix = tokens.GetNextToken();
2586  pos += prefix.size() + 1;
2587 
2588  tmp = tokens.GetNextToken();
2589  pos += tmp.size() + 1; // NumOfPins, unused.
2590 
2591  tmp = tokens.GetNextToken(); // Pin name offset.
2592 
2593  if( !tmp.ToLong( &num ) )
2594  THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
2595  aReader.LineNumber(), pos );
2596 
2597  pos += tmp.size() + 1;
2598  part->SetPinNameOffset( (int)num );
2599 
2600  tmp = tokens.GetNextToken(); // Show pin numbers.
2601 
2602  if( !( tmp == "Y" || tmp == "N") )
2603  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2604  aReader.LineNumber(), pos );
2605 
2606  pos += tmp.size() + 1;
2607  part->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
2608 
2609  tmp = tokens.GetNextToken(); // Show pin names.
2610 
2611  if( !( tmp == "Y" || tmp == "N") )
2612  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2613  aReader.LineNumber(), pos );
2614 
2615  pos += tmp.size() + 1;
2616  part->SetShowPinNames( ( tmp == "N" ) ? false : true );
2617 
2618  tmp = tokens.GetNextToken(); // Number of units.
2619 
2620  if( !tmp.ToLong( &num ) )
2621  THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
2622  aReader.LineNumber(), pos );
2623 
2624  pos += tmp.size() + 1;
2625  part->SetUnitCount( (int)num );
2626 
2627  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2628  if( part->GetUnitCount() < 1 )
2629  part->SetUnitCount( 1 );
2630 
2631  // Copy part name and prefix.
2632 
2633  // The root alias is added to the alias list by SetName() which is called by SetText().
2634  if( name.IsEmpty() )
2635  {
2636  part->SetName( "~" );
2637  }
2638  else if( name[0] != '~' )
2639  {
2640  part->SetName( name );
2641  }
2642  else
2643  {
2644  part->SetName( name.Right( name.Length() - 1 ) );
2645  part->GetValueField().SetVisible( false );
2646  }
2647 
2648  // Don't set the library alias, this is determined by the symbol library table.
2649  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2650 
2651  // There are some code paths in SetText() that do not set the root alias to the
2652  // alias list so add it here if it didn't get added by SetText().
2653  if( !part->HasAlias( part->GetName() ) )
2654  part->AddAlias( part->GetName() );
2655 
2656  LIB_FIELD& reference = part->GetReferenceField();
2657 
2658  if( prefix == "~" )
2659  {
2660  reference.Empty();
2661  reference.SetVisible( false );
2662  }
2663  else
2664  {
2665  reference.SetText( prefix );
2666  }
2667 
2668  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2669  // The was no concept of interchangeable multiple unit symbols.
2671  {
2672  // Nothing needs to be set since the default setting for symbols with multiple
2673  // units were never interchangeable. Just parse the 0 an move on.
2674  tmp = tokens.GetNextToken();
2675  pos += tmp.size() + 1;
2676  }
2677  else
2678  {
2679  tmp = tokens.GetNextToken();
2680 
2681  if( tmp == "L" )
2682  part->LockUnits( true );
2683  else if( tmp == "F" || tmp == "0" )
2684  part->LockUnits( false );
2685  else
2686  THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
2687  aReader.LineNumber(), pos );
2688 
2689  pos += tmp.size() + 1;
2690  }
2691 
2692  // There is the optional power component flag.
2693  if( tokens.HasMoreTokens() )
2694  {
2695  tmp = tokens.GetNextToken();
2696 
2697  if( tmp == "P" )
2698  part->SetPower();
2699  else if( tmp == "N" )
2700  part->SetNormal();
2701  else
2702  THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
2703  aReader.LineNumber(), pos );
2704  }
2705 
2706  line = aReader.ReadLine();
2707 
2708  // Read lines until "ENDDEF" is found.
2709  while( line )
2710  {
2711  if( *line == '#' ) // Comment
2712  ;
2713  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2714  continue;
2715  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2716  loadAliases( part, aReader );
2717  else if( *line == 'F' ) // Fields
2718  loadField( part, aReader );
2719  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2720  loadDrawEntries( part, aReader );
2721  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2722  loadFootprintFilters( part, aReader );
2723  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2724  {
2725  // Add aliases
2726  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2727  {
2728  LIB_ALIAS* alias = part->GetAlias( ii );
2729  const wxString& aliasName = alias->GetName();
2730  auto it = m_aliases.find( aliasName );
2731 
2732  if( it != m_aliases.end() )
2733  {
2734  // Find a new name for the alias
2735  wxString newName;
2736  int idx = 0;
2737  LIB_ALIAS_MAP::const_iterator jt;
2738 
2739  do
2740  {
2741  newName = wxString::Format( "%s_%d", aliasName, idx );
2742  jt = m_aliases.find( newName );
2743  ++idx;
2744  }
2745  while( jt != m_aliases.end() );
2746 
2747  wxLogWarning( "Symbol name conflict in library:\n%s\n"
2748  "'%s' has been renamed to '%s'",
2749  m_fileName, aliasName, newName );
2750 
2751  if( alias->IsRoot() )
2752  part->SetName( newName );
2753  else
2754  alias->SetName( newName );
2755 
2756  m_aliases[newName] = alias;
2757  }
2758  else
2759  {
2760  m_aliases[aliasName] = alias;
2761  }
2762  }
2763 
2764  return part.release();
2765  }
2766 
2767  line = aReader.ReadLine();
2768  }
2769 
2770  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2771 }
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
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:188
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void loadAliases(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
bool IsRoot() const override
For symbols having aliases, IsRoot() indicates the principal item.
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:518
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:244
Define a library symbol object.
void loadField(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
void loadDrawEntries(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
#define SCH_PARSE_ERROR(text, reader, pos)
const wxString & GetName() const override
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void loadFootprintFilters(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_PIN * SCH_LEGACY_PLUGIN_CACHE::loadPin ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3253 of file sch_legacy_plugin.cpp.

References LINE_READER::GetSource(), LINE_READER::Line(), LINE_READER::LineNumber(), LIB_PIN::m_attributes, LIB_ITEM::m_Convert, LIB_PIN::m_length, LIB_PIN::m_name, LIB_PIN::m_nameTextSize, LIB_PIN::m_number, LIB_PIN::m_numTextSize, LIB_PIN::m_orientation, LIB_PIN::m_position, LIB_PIN::m_shape, LIB_PIN::m_type, LIB_ITEM::m_Unit, PIN_BIDI, PIN_INPUT, PIN_INVISIBLE, PIN_NC, PIN_OPENCOLLECTOR, PIN_OPENEMITTER, PIN_OUTPUT, PIN_PASSIVE, PIN_POWER_IN, PIN_POWER_OUT, PIN_TRISTATE, PIN_UNSPECIFIED, PINSHAPE_CLOCK, PINSHAPE_CLOCK_LOW, PINSHAPE_FALLING_EDGE_CLOCK, PINSHAPE_INPUT_LOW, PINSHAPE_INVERTED, PINSHAPE_INVERTED_CLOCK, PINSHAPE_LINE, PINSHAPE_NONLOGIC, PINSHAPE_OUTPUT_LOW, SCH_PARSE_ERROR, strCompare(), and THROW_PARSE_ERROR.

Referenced by loadDrawEntries().

3255 {
3256  const char* line = aReader.Line();
3257 
3258  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3259 
3260  LIB_PIN* pin = new LIB_PIN( aPart.get() );
3261 
3262  size_t pos = 2; // "X" plus ' ' space character.
3263  wxString tmp;
3264  wxString utf8Line = wxString::FromUTF8( line );
3265  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3266 
3267  if( tokens.CountTokens() < 11 )
3268  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3269 
3270  pin->m_name = tokens.GetNextToken();
3271  pos += pin->m_name.size() + 1;
3272  pin->m_number = tokens.GetNextToken();
3273  pos += pin->m_number.size() + 1;
3274 
3275  long num;
3276  wxPoint position;
3277 
3278  tmp = tokens.GetNextToken();
3279 
3280  if( !tmp.ToLong( &num ) )
3281  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3282  aReader.LineNumber(), pos );
3283 
3284  pos += tmp.size() + 1;
3285  position.x = (int) num;
3286 
3287  tmp = tokens.GetNextToken();
3288 
3289  if( !tmp.ToLong( &num ) )
3290  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3291  aReader.LineNumber(), pos );
3292 
3293  pos += tmp.size() + 1;
3294  position.y = (int) num;
3295  pin->m_position = position;
3296 
3297  tmp = tokens.GetNextToken();
3298 
3299  if( !tmp.ToLong( &num ) )
3300  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3301  aReader.LineNumber(), pos );
3302 
3303  pos += tmp.size() + 1;
3304  pin->m_length = (int) num;
3305 
3306 
3307  tmp = tokens.GetNextToken();
3308 
3309  if( tmp.size() > 1 )
3310  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3311  aReader.LineNumber(), pos );
3312 
3313  pos += tmp.size() + 1;
3314  pin->m_orientation = tmp[0];
3315 
3316  tmp = tokens.GetNextToken();
3317 
3318  if( !tmp.ToLong( &num ) )
3319  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3320  aReader.LineNumber(), pos );
3321 
3322  pos += tmp.size() + 1;
3323  pin->m_numTextSize = (int) num;
3324 
3325  tmp = tokens.GetNextToken();
3326 
3327  if( !tmp.ToLong( &num ) )
3328  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3329  aReader.LineNumber(), pos );
3330 
3331  pos += tmp.size() + 1;
3332  pin->m_nameTextSize = (int) num;
3333 
3334  tmp = tokens.GetNextToken();
3335 
3336  if( !tmp.ToLong( &num ) )
3337  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3338  aReader.LineNumber(), pos );
3339 
3340  pos += tmp.size() + 1;
3341  pin->m_Unit = (int) num;
3342 
3343  tmp = tokens.GetNextToken();
3344 
3345  if( !tmp.ToLong( &num ) )
3346  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3347  aReader.LineNumber(), pos );
3348 
3349  pos += tmp.size() + 1;
3350  pin->m_Convert = (int) num;
3351 
3352  tmp = tokens.GetNextToken();
3353 
3354  if( tmp.size() != 1 )
3355  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3356  aReader.LineNumber(), pos );
3357 
3358  pos += tmp.size() + 1;
3359  char type = tmp[0];
3360 
3361  wxString attributes;
3362 
3363  switch( type )
3364  {
3365  case 'I': pin->m_type = PIN_INPUT; break;
3366  case 'O': pin->m_type = PIN_OUTPUT; break;
3367  case 'B': pin->m_type = PIN_BIDI; break;
3368  case 'T': pin->m_type = PIN_TRISTATE; break;
3369  case 'P': pin->m_type = PIN_PASSIVE; break;
3370  case 'U': pin->m_type = PIN_UNSPECIFIED; break;
3371  case 'W': pin->m_type = PIN_POWER_IN; break;
3372  case 'w': pin->m_type = PIN_POWER_OUT; break;
3373  case 'C': pin->m_type = PIN_OPENCOLLECTOR; break;
3374  case 'E': pin->m_type = PIN_OPENEMITTER; break;
3375  case 'N': pin->m_type = PIN_NC; break;
3376  default: THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(),
3377  aReader.Line(), aReader.LineNumber(), pos );
3378  }
3379 
3380  // Optional
3381  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3382  {
3383  tmp = tokens.GetNextToken();
3384 
3385  enum
3386  {
3387  INVERTED = 1 << 0,
3388  CLOCK = 1 << 1,
3389  LOWLEVEL_IN = 1 << 2,
3390  LOWLEVEL_OUT = 1 << 3,
3391  FALLING_EDGE = 1 << 4,
3392  NONLOGIC = 1 << 5
3393  };
3394 
3395  int flags = 0;
3396 
3397  for( int j = tmp.size(); j > 0; )
3398  {
3399  switch( tmp[--j].GetValue() )
3400  {
3401  case '~': break;
3402  case 'N': pin->m_attributes |= PIN_INVISIBLE; break;
3403  case 'I': flags |= INVERTED; break;
3404  case 'C': flags |= CLOCK; break;
3405  case 'L': flags |= LOWLEVEL_IN; break;
3406  case 'V': flags |= LOWLEVEL_OUT; break;
3407  case 'F': flags |= FALLING_EDGE; break;
3408  case 'X': flags |= NONLOGIC; break;
3409  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3410  aReader.Line(), aReader.LineNumber(), pos );
3411  }
3412 
3413  pos += 1;
3414  }
3415 
3416  switch( flags )
3417  {
3418  case 0: pin->m_shape = PINSHAPE_LINE; break;
3419  case INVERTED: pin->m_shape = PINSHAPE_INVERTED; break;
3420  case CLOCK: pin->m_shape = PINSHAPE_CLOCK; break;
3421  case INVERTED | CLOCK: pin->m_shape = PINSHAPE_INVERTED_CLOCK; break;
3422  case LOWLEVEL_IN: pin->m_shape = PINSHAPE_INPUT_LOW; break;
3423  case LOWLEVEL_IN | CLOCK: pin->m_shape = PINSHAPE_CLOCK_LOW; break;
3424  case LOWLEVEL_OUT: pin->m_shape = PINSHAPE_OUTPUT_LOW; break;
3425  case FALLING_EDGE: pin->m_shape = PINSHAPE_FALLING_EDGE_CLOCK; break;
3426  case NONLOGIC: pin->m_shape = PINSHAPE_NONLOGIC; break;
3427  default: SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3428  }
3429  }
3430 
3431  return pin;
3432 }
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:85
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:78
int m_numTextSize
Definition: lib_pin.h:84
int m_Unit
Unit identification for multiple parts per package.
wxString m_name
Definition: lib_pin.h:82
int m_length
Length of the pin.
Definition: lib_pin.h:76
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:77
wxString m_number
Definition: lib_pin.h:83
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define PIN_INVISIBLE
Definition: lib_pin.h:46
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:81
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:75
#define SCH_PARSE_ERROR(text, reader, pos)
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:80
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
int m_Convert
Shape identification for alternate body styles.
LIB_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3435 of file sch_legacy_plugin.cpp.

References LIB_POLYLINE::AddPoint(), i, LINE_READER::Line(), parseFillMode(), parseInt(), LIB_POLYLINE::Reserve(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetUnit(), LIB_POLYLINE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

3437 {
3438  const char* line = aReader.Line();
3439 
3440  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3441 
3442  LIB_POLYLINE* polyLine = new LIB_POLYLINE( aPart.get() );
3443 
3444  int points = parseInt( aReader, line, &line );
3445  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3446  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3447  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3448  polyLine->Reserve( points );
3449 
3450  wxPoint pt;
3451 
3452  for( int i = 0; i < points; i++ )
3453  {
3454  pt.x = parseInt( aReader, line, &line );
3455  pt.y = parseInt( aReader, line, &line );
3456  polyLine->AddPoint( pt );
3457  }
3458 
3459  if( *line != 0 )
3460  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3461 
3462  return polyLine;
3463 }
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 SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_polyline.h:115
void Reserve(size_t aPointCount)
Definition: lib_polyline.h:65
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void AddPoint(const wxPoint &aPoint)
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFillMode)
void SetConvert(int aConvert)
void SetUnit(int aUnit)
size_t i
Definition: json11.cpp:597
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3221 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3223 {
3224  const char* line = aReader.Line();
3225 
3226  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3227 
3228  LIB_RECTANGLE* rectangle = new LIB_RECTANGLE( aPart.get() );
3229 
3230  wxPoint pos;
3231 
3232  pos.x = parseInt( aReader, line, &line );
3233  pos.y = parseInt( aReader, line, &line );
3234  rectangle->SetPosition( pos );
3235 
3236  wxPoint end;
3237 
3238  end.x = parseInt( aReader, line, &line );
3239  end.y = parseInt( aReader, line, &line );
3240  rectangle->SetEnd( end );
3241 
3242  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3243  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3244  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3245 
3246  if( *line != 0 )
3247  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3248 
3249  return rectangle;
3250 }
void SetPosition(const wxPoint &aPosition)
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 SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
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)
void SetFillMode(FILL_T aFillMode)
void SetConvert(int aConvert)
void SetUnit(int aUnit)
void SetEnd(const wxPoint &aEnd)
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 3131 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, EDA_TEXT::SetBold(), LIB_ITEM::SetConvert(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), LIB_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextSize(), LIB_ITEM::SetUnit(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), str, and strCompare().

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

3133 {
3134  const char* line = aReader.Line();
3135 
3136  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3137 
3138  LIB_TEXT* text = new LIB_TEXT( aPart.get() );
3139 
3140  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3141 
3142  wxPoint center;
3143 
3144  center.x = parseInt( aReader, line, &line );
3145  center.y = parseInt( aReader, line, &line );
3146  text->SetPosition( center );
3147 
3148  wxSize size;
3149 
3150  size.x = size.y = parseInt( aReader, line, &line );
3151  text->SetTextSize( size );
3152  text->SetVisible( !parseInt( aReader, line, &line ) );
3153  text->SetUnit( parseInt( aReader, line, &line ) );
3154  text->SetConvert( parseInt( aReader, line, &line ) );
3155 
3156  wxString str;
3157 
3158  // If quoted string loading fails, load as not quoted string.
3159  if( *line == '"' )
3160  parseQuotedString( str, aReader, line, &line );
3161  else
3162  {
3163  parseUnquotedString( str, aReader, line, &line );
3164 
3165  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3166  str.Replace( "~", " " );
3167  }
3168 
3169  if( !str.IsEmpty() )
3170  {
3171  // convert two apostrophes back to double quote
3172  str.Replace( "''", "\"" );
3173  }
3174 
3175  text->SetText( str );
3176 
3177  // Here things are murky and not well defined. At some point it appears the format
3178  // was changed to add text properties. However rather than add the token to the end of
3179  // the text definition, it was added after the string and no mention if the file
3180  // verion was bumped or not so this code make break on very old component libraries.
3181  //
3182  // Update: apparently even in the latest version this can be different so added a test
3183  // for end of line before checking for the text properties.
3184  if( LIB_VERSION( m_versionMajor, m_versionMinor ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3185  {
3186  if( strCompare( "Italic", line, &line ) )
3187  text->SetItalic( true );
3188  else if( !strCompare( "Normal", line, &line ) )
3189  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3190 
3191  if( parseInt( aReader, line, &line ) > 0 )
3192  text->SetBold( true );
3193 
3194  // Some old libaries version > 2.0 do not have these options for text justification:
3195  if( !is_eol( *line ) )
3196  {
3197  switch( parseChar( aReader, line, &line ) )
3198  {
3199  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3200  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3201  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3202  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3203  aReader, line );
3204  }
3205 
3206  switch( parseChar( aReader, line, &line ) )
3207  {
3208  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3209  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3210  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3211  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3212  aReader, line );
3213  }
3214  }
3215  }
3216 
3217  return text;
3218 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
void SetPosition(const wxPoint &aPosition)
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.
void SetItalic(bool isItalic)
Definition: eda_text.h:182
void SetVisible(bool aVisible)
Definition: eda_text.h:188
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
const string & str
Definition: json11.cpp:596
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:207
static bool is_eol(char c)
void SetConvert(int aConvert)
void SetUnit(int aUnit)
#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.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
void SetText(const wxString &aText) override
Sets the text item string to aText.
Definition: lib_text.cpp:350
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetBold(bool aBold)
Definition: eda_text.h:185
FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode ( FILE_LINE_READER aReader,
const char *  aLine,
const char **  aOutput 
)
private

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

3027 {
3028  switch( parseChar( aReader, aLine, aOutput ) )
3029  {
3030  case 'F': return FILLED_SHAPE;
3031  case 'f': return FILLED_WITH_BG_BODYCOLOR;
3032  case 'N': return NO_FILL;
3033  default: SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3034  }
3035 }
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)
LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

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

2281 {
2282  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2283 
2284  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2285 
2286  if( it == m_aliases.end() )
2287  return NULL;
2288 
2289  // If the entry pointer doesn't match the name it is mapped to in the library, we
2290  // have done something terribly wrong.
2291  wxCHECK_MSG( *it->second == aAlias, NULL,
2292  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2293  "> from library cache <" + m_libFileName.GetName() + ">." );
2294 
2295  LIB_ALIAS* alias = aAlias;
2296  LIB_PART* part = alias->GetPart();
2297 
2298  alias = part->RemoveAlias( alias );
2299 
2300  if( !alias )
2301  {
2302  delete part;
2303 
2304  if( m_aliases.size() > 1 )
2305  {
2306  LIB_ALIAS_MAP::iterator next = it;
2307  next++;
2308 
2309  if( next == m_aliases.end() )
2310  next = m_aliases.begin();
2311 
2312  alias = next->second;
2313  }
2314  }
2315 
2316  m_aliases.erase( it );
2317  m_isModified = true;
2318  ++m_modHash;
2319  return alias;
2320 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol object.
const wxString & GetName() const override
void RemoveAlias(const wxString &aName)
void SCH_LEGACY_PLUGIN_CACHE::Save ( bool  aSaveDocFile = true)

Save the entire library to file m_libFileName;.

Definition at line 3522 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

3523 {
3524  if( !m_isModified )
3525  return;
3526 
3527  // Write through symlinks, don't replace them
3528  wxFileName fn = GetRealFile();
3529 
3530  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) );
3531  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3532  formatter->Print( 0, "#encoding utf-8\n");
3533 
3534  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3535  {
3536  if( !it->second->IsRoot() )
3537  continue;
3538 
3539  saveSymbol( it->second->GetPart(), formatter );
3540  }
3541 
3542  formatter->Print( 0, "#\n#End Library\n" );
3543  formatter.reset();
3544 
3545  m_fileModTime = fn.GetModificationTime();
3546  m_isModified = false;
3547 
3548  if( aSaveDocFile )
3549  saveDocFile();
3550 }
#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
wxFileName GetRealFile() const
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 3723 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, and EDA_ITEM::Type().

Referenced by saveSymbol().

3725 {
3726  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3727 
3728  int x1 = aArc->GetFirstRadiusAngle();
3729 
3730  if( x1 > 1800 )
3731  x1 -= 3600;
3732 
3733  int x2 = aArc->GetSecondRadiusAngle();
3734 
3735  if( x2 > 1800 )
3736  x2 -= 3600;
3737 
3738  aFormatter->Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3739  aArc->GetPosition().x, aArc->GetPosition().y,
3740  aArc->GetRadius(), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3741  aArc->GetWidth(), fill_tab[aArc->GetFillMode()],
3742  aArc->GetStart().x, aArc->GetStart().y,
3743  aArc->GetEnd().x, aArc->GetEnd().y );
3744 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
FILL_T GetFillMode() const
int GetSecondRadiusAngle() const
Definition: lib_arc.h:146
wxPoint GetStart() const
Definition: lib_arc.h:148
int GetUnit() const
int GetFirstRadiusAngle() const
Definition: lib_arc.h:142
wxPoint GetEnd() const
Definition: lib_arc.h:152
int GetRadius() const
Definition: lib_arc.h:138
int GetWidth() const override
Return the width of the draw item.
Definition: lib_arc.h:132
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_arc.h:121
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveBezier ( LIB_BEZIER aBezier,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3747 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3749 {
3750  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3751 
3752  aFormatter->Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3753  aBezier->GetUnit(), aBezier->GetConvert(), aBezier->GetWidth() );
3754 
3755  for( const auto& pt : aBezier->GetPoints() )
3756  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3757 
3758  aFormatter->Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3759 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:76
int GetWidth() const override
Return the width of the draw item.
Definition: lib_bezier.h:102
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 3762 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, and EDA_ITEM::Type().

Referenced by saveSymbol().

3764 {
3765  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3766 
3767  aFormatter->Print( 0, "C %d %d %d %d %d %d %c\n",
3768  aCircle->GetPosition().x, aCircle->GetPosition().y,
3769  aCircle->GetRadius(), aCircle->GetUnit(), aCircle->GetConvert(),
3770  aCircle->GetWidth(), fill_tab[aCircle->GetFillMode()] );
3771 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
FILL_T GetFillMode() const
int GetUnit() const
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_circle.h:86
int GetWidth() const override
Return the width of the draw item.
Definition: lib_circle.h:97
int GetRadius() const
Definition: lib_circle.h:103
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 4013 of file sch_legacy_plugin.cpp.

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

Referenced by Save().

4014 {
4015  wxFileName fileName = m_libFileName;
4016 
4017  fileName.SetExt( DOC_EXT );
4018  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
4019 
4020  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
4021 
4022  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
4023  {
4024  wxString description = it->second->GetDescription();
4025  wxString keyWords = it->second->GetKeyWords();
4026  wxString docFileName = it->second->GetDocFileName();
4027 
4028  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
4029  continue;
4030 
4031  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
4032 
4033  if( !description.IsEmpty() )
4034  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
4035 
4036  if( !keyWords.IsEmpty() )
4037  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
4038 
4039  if( !docFileName.IsEmpty() )
4040  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
4041 
4042  formatter.Print( 0, "$ENDCMP\n" );
4043  }
4044 
4045  formatter.Print( 0, "#\n#End Doc Library\n" );
4046 }
#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 3774 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, and EDA_ITEM::Type().

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

3776 {
3777  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3778 
3779  int hjustify, vjustify;
3780  int id = aField->GetId();
3781  wxString text = aField->m_Text;
3782 
3783  hjustify = 'C';
3784 
3785  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3786  hjustify = 'L';
3787  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3788  hjustify = 'R';
3789 
3790  vjustify = 'C';
3791 
3792  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3793  vjustify = 'B';
3794  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3795  vjustify = 'T';
3796 
3797  aFormatter->Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3798  id,
3799  EscapedUTF8( text ).c_str(), // wraps in quotes
3800  aField->GetTextPos().x, aField->GetTextPos().y, aField->GetTextWidth(),
3801  aField->GetTextAngle() == 0 ? 'H' : 'V',
3802  aField->IsVisible() ? 'V' : 'I',
3803  hjustify, vjustify,
3804  aField->IsItalic() ? 'I' : 'N',
3805  aField->IsBold() ? 'B' : 'N' );
3806 
3807  /* Save field name, if necessary
3808  * Field name is saved only if it is not the default name.
3809  * Just because default name depends on the language and can change from
3810  * a country to another
3811  */
3812  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3813 
3814  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3815  aFormatter->Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3816 
3817  aFormatter->Print( 0, "\n" );
3818 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
wxString m_Text
Definition: eda_text.h:374
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
bool IsItalic() const
Definition: eda_text.h:183
int GetTextWidth() const
Definition: eda_text.h:231
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:203
bool IsBold() const
Definition: eda_text.h:186
double GetTextAngle() const
Definition: eda_text.h:177
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:214
int GetId() const
Definition: lib_field.h:140
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:204
bool IsVisible() const
Definition: lib_field.h:168
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 3821 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, and EDA_ITEM::Type().

Referenced by saveSymbol().

3823 {
3824  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3825 
3826  int Etype;
3827 
3828  switch( aPin->GetType() )
3829  {
3830  default:
3831  case PIN_INPUT:
3832  Etype = 'I';
3833  break;
3834 
3835  case PIN_OUTPUT:
3836  Etype = 'O';
3837  break;
3838 
3839  case PIN_BIDI:
3840  Etype = 'B';
3841  break;
3842 
3843  case PIN_TRISTATE:
3844  Etype = 'T';
3845  break;
3846 
3847  case PIN_PASSIVE:
3848  Etype = 'P';
3849  break;
3850 
3851  case PIN_UNSPECIFIED:
3852  Etype = 'U';
3853  break;
3854 
3855  case PIN_POWER_IN:
3856  Etype = 'W';
3857  break;
3858 
3859  case PIN_POWER_OUT:
3860  Etype = 'w';
3861  break;
3862 
3863  case PIN_OPENCOLLECTOR:
3864  Etype = 'C';
3865  break;
3866 
3867  case PIN_OPENEMITTER:
3868  Etype = 'E';
3869  break;
3870 
3871  case PIN_NC:
3872  Etype = 'N';
3873  break;
3874  }
3875 
3876  if( !aPin->GetName().IsEmpty() )
3877  aFormatter->Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
3878  else
3879  aFormatter->Print( 0, "X ~" );
3880 
3881  aFormatter->Print( 0, " %s %d %d %d %c %d %d %d %d %c",
3882  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
3883  aPin->GetPosition().x, aPin->GetPosition().y,
3884  (int) aPin->GetLength(), (int) aPin->GetOrientation(),
3885  aPin->GetNumberTextSize(), aPin->GetNameTextSize(),
3886  aPin->GetUnit(), aPin->GetConvert(), Etype );
3887 
3888  if( aPin->GetShape() || !aPin->IsVisible() )
3889  aFormatter->Print( 0, " " );
3890 
3891  if( !aPin->IsVisible() )
3892  aFormatter->Print( 0, "N" );
3893 
3894  switch( aPin->GetShape() )
3895  {
3896  case PINSHAPE_LINE:
3897  break;
3898 
3899  case PINSHAPE_INVERTED:
3900  aFormatter->Print( 0, "I" );
3901  break;
3902 
3903  case PINSHAPE_CLOCK:
3904  aFormatter->Print( 0, "C" );
3905  break;
3906 
3908  aFormatter->Print( 0, "IC" );
3909  break;
3910 
3911  case PINSHAPE_INPUT_LOW:
3912  aFormatter->Print( 0, "L" );
3913  break;
3914 
3915  case PINSHAPE_CLOCK_LOW:
3916  aFormatter->Print( 0, "CL" );
3917  break;
3918 
3919  case PINSHAPE_OUTPUT_LOW:
3920  aFormatter->Print( 0, "V" );
3921  break;
3922 
3924  aFormatter->Print( 0, "F" );
3925  break;
3926 
3927  case PINSHAPE_NONLOGIC:
3928  aFormatter->Print( 0, "X" );
3929  break;
3930 
3931  default:
3932  assert( !"Invalid pin shape" );
3933  }
3934 
3935  aFormatter->Print( 0, "\n" );
3936 
3937  aPin->ClearFlags( IS_CHANGED );
3938 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
int GetUnit() const
int GetNameTextSize() const
Definition: lib_pin.h:192
int GetOrientation() const
Definition: lib_pin.h:221
int GetNumberTextSize() const
Definition: lib_pin.h:219
const wxString & GetNumber() const
Definition: lib_pin.h:194
const wxString & GetName() const
Definition: lib_pin.h:166
#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:110
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:251
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:362
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:463
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
int GetLength()
Definition: lib_pin.h:301
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:235
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::savePolyLine ( LIB_POLYLINE aPolyLine,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

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

3943 {
3944  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
3945 
3946  int ccount = aPolyLine->GetCornerCount();
3947 
3948  aFormatter->Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
3949  aPolyLine->GetWidth() );
3950 
3951  for( const auto& pt : aPolyLine->GetPolyPoints() )
3952  {
3953  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3954  }
3955 
3956  aFormatter->Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
3957 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:68
unsigned GetCornerCount() const
Definition: lib_polyline.h:78
int GetWidth() const override
Return the width of the draw item.
Definition: lib_polyline.h:113
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 3960 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, and EDA_ITEM::Type().

Referenced by saveSymbol().

3962 {
3963  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
3964  "Invalid LIB_RECTANGLE object." );
3965 
3966  aFormatter->Print( 0, "S %d %d %d %d %d %d %d %c\n",
3967  aRectangle->GetPosition().x, aRectangle->GetPosition().y,
3968  aRectangle->GetEnd().x, aRectangle->GetEnd().y,
3969  aRectangle->GetUnit(), aRectangle->GetConvert(),
3970  aRectangle->GetWidth(), fill_tab[aRectangle->GetFillMode()] );
3971 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
FILL_T GetFillMode() const
int GetUnit() const
int GetWidth() const override
Return the width of the draw item.
wxPoint GetEnd() const
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_rectangle.h:91
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveSymbol ( LIB_PART aSymbol,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3553 of file sch_legacy_plugin.cpp.

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_PART::GetAliasCount(), LIB_PART::GetAliasNames(), LIB_PART::GetDateLastEdition(), LIB_PART::GetDrawItems(), LIB_PART::GetFields(), LIB_PART::GetFootprints(), LIB_PART::GetPinNameOffset(), LIB_PART::GetReferenceField(), GetText(), EDA_TEXT::GetText(), LIB_PART::GetUnitCount(), LIB_PART::GetValueField(), i, LIB_PART::IsPower(), LIB_FIELD::IsVisible(), LIB_ARC_T, LIB_BEZIER_T, LIB_CIRCLE_T, LIB_FIELD_T, LIB_PIN_T, LIB_POLYLINE_T, LIB_RECTANGLE_T, LIB_TEXT_T, MANDATORY_FIELDS, min, saveArc(), saveBezier(), saveCircle(), saveField(), savePin(), savePolyLine(), saveRectangle(), saveText(), LIB_PART::ShowPinNames(), LIB_PART::ShowPinNumbers(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort(), TO_UTF8, and LIB_PART::UnitsLocked().

Referenced by Save().

3555 {
3556  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
3557 
3558  LIB_FIELD& value = aSymbol->GetValueField();
3559 
3560  // First line: it s a comment (component name for readers)
3561  aFormatter->Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3562 
3563  // Save data
3564  aFormatter->Print( 0, "DEF" );
3565 
3566  if( value.IsVisible() )
3567  {
3568  aFormatter->Print( 0, " %s", TO_UTF8( value.GetText() ) );
3569  }
3570  else
3571  {
3572  aFormatter->Print( 0, " ~%s", TO_UTF8( value.GetText() ) );
3573  }
3574 
3575  LIB_FIELD& reference = aSymbol->GetReferenceField();
3576 
3577  if( !reference.GetText().IsEmpty() )
3578  {
3579  aFormatter->Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3580  }
3581  else
3582  {
3583  aFormatter->Print( 0, " ~" );
3584  }
3585 
3586  aFormatter->Print( 0, " %d %d %c %c %d %c %c\n",
3587  0, aSymbol->GetPinNameOffset(),
3588  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3589  aSymbol->ShowPinNames() ? 'Y' : 'N',
3590  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3591  aSymbol->IsPower() ? 'P' : 'N' );
3592 
3593  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3594 
3595  if( dateModified != 0 )
3596  {
3597  int sec = dateModified & 63;
3598  int min = ( dateModified >> 6 ) & 63;
3599  int hour = ( dateModified >> 12 ) & 31;
3600  int day = ( dateModified >> 17 ) & 31;
3601  int mon = ( dateModified >> 22 ) & 15;
3602  int year = ( dateModified >> 26 ) + 1990;
3603 
3604  aFormatter->Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3605  }
3606 
3607  LIB_FIELDS fields;
3608  aSymbol->GetFields( fields );
3609 
3610  // Mandatory fields:
3611  // may have their own save policy so there is a separate loop for them.
3612  // Empty fields are saved, because the user may have set visibility,
3613  // size and orientation
3614  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3615  {
3616  saveField( &fields[i], aFormatter );
3617  }
3618 
3619  // User defined fields:
3620  // may have their own save policy so there is a separate loop for them.
3621 
3622  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3623 
3624  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3625  {
3626  // There is no need to save empty fields, i.e. no reason to preserve field
3627  // names now that fields names come in dynamically through the template
3628  // fieldnames.
3629  if( !fields[i].GetText().IsEmpty() )
3630  {
3631  fields[i].SetId( fieldId++ );
3632  saveField( &fields[i], aFormatter );
3633  }
3634  }
3635 
3636  // Save the alias list: a line starting by "ALIAS". The first alias is the root
3637  // and has the same name as the component. In the old library file format this
3638  // alias does not get added to the alias list.
3639  if( aSymbol->GetAliasCount() > 1 )
3640  {
3641  wxArrayString aliases = aSymbol->GetAliasNames();
3642 
3643  aFormatter->Print( 0, "ALIAS" );
3644 
3645  for( unsigned i = 1; i < aliases.size(); i++ )
3646  {
3647  aFormatter->Print( 0, " %s", TO_UTF8( aliases[i] ) );
3648  }
3649 
3650  aFormatter->Print( 0, "\n" );
3651  }
3652 
3653  wxArrayString footprints = aSymbol->GetFootprints();
3654 
3655  // Write the footprint filter list
3656  if( footprints.GetCount() != 0 )
3657  {
3658  aFormatter->Print( 0, "$FPLIST\n" );
3659 
3660  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3661  {
3662  aFormatter->Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3663  }
3664 
3665  aFormatter->Print( 0, "$ENDFPLIST\n" );
3666  }
3667 
3668  // Save graphics items (including pins)
3669  if( !aSymbol->GetDrawItems().empty() )
3670  {
3671  // Sort the draw items in order to editing a file editing by hand.
3672  aSymbol->GetDrawItems().sort();
3673 
3674  aFormatter->Print( 0, "DRAW\n" );
3675 
3676  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3677  {
3678  switch( item.Type() )
3679  {
3680  case LIB_FIELD_T: // Fields have already been saved above.
3681  continue;
3682 
3683  case LIB_ARC_T:
3684  saveArc( (LIB_ARC*) &item, aFormatter );
3685  break;
3686 
3687  case LIB_BEZIER_T:
3688  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3689  break;
3690 
3691  case LIB_CIRCLE_T:
3692  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3693  break;
3694 
3695  case LIB_PIN_T:
3696  savePin( (LIB_PIN* ) &item, aFormatter );
3697  break;
3698 
3699  case LIB_POLYLINE_T:
3700  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3701  break;
3702 
3703  case LIB_RECTANGLE_T:
3704  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3705  break;
3706 
3707  case LIB_TEXT_T:
3708  saveText( ( LIB_TEXT* ) &item, aFormatter );
3709  break;
3710 
3711  default:
3712  ;
3713  }
3714  }
3715 
3716  aFormatter->Print( 0, "ENDDRAW\n" );
3717  }
3718 
3719  aFormatter->Print( 0, "ENDDEF\n" );
3720 }
bool UnitsLocked() const
Check whether part units are interchangeable.
int GetPinNameOffset()
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
bool IsPower() const
Define a symbol library graphical text item.
Definition: lib_text.h:44
void saveRectangle(LIB_RECTANGLE *aRectangle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Field object used in symbol libraries.
Definition: lib_field.h:59
void sort()
Definition: multivector.h:229
LIB_FIELD & GetValueField()
Return reference to the value field.
size_t GetAliasCount() const
void savePin(LIB_PIN *aPin, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveCircle(LIB_CIRCLE *aCircle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
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:143
timestamp_t GetDateLastEdition() const
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
wxArrayString & GetFootprints()
int GetUnitCount() const
bool IsVisible() const
Definition: lib_field.h:168
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:261
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
void savePolyLine(LIB_POLYLINE *aPolyLine, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveArc(LIB_ARC *aArc, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveField(LIB_FIELD *aField, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveBezier(LIB_BEZIER *aBezier, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void GetFields(LIB_FIELDS &aList)
Return a list of fields within 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 3974 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, and EDA_ITEM::Type().

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

3976 {
3977  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
3978 
3979  wxString text = aText->GetText();
3980 
3981  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
3982  {
3983  // convert double quote to similar-looking two apostrophes
3984  text.Replace( wxT( "\"" ), wxT( "''" ) );
3985  text = wxT( "\"" ) + text + wxT( "\"" );
3986  }
3987 
3988  aFormatter->Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
3989  aText->GetTextPos().x, aText->GetTextPos().y,
3990  aText->GetTextWidth(), !aText->IsVisible(),
3991  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
3992 
3993  aFormatter->Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
3994 
3995  char hjustify = 'C';
3996 
3997  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3998  hjustify = 'L';
3999  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4000  hjustify = 'R';
4001 
4002  char vjustify = 'C';
4003 
4004  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4005  vjustify = 'B';
4006  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4007  vjustify = 'T';
4008 
4009  aFormatter->Print( 0, " %c %c\n", hjustify, vjustify );
4010 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
const wxPoint & GetTextPos() const
Definition: eda_text.h:237
bool IsItalic() const
Definition: eda_text.h:183
int GetUnit() const
int GetTextWidth() const
Definition: eda_text.h:231
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:203
bool IsBold() const
Definition: eda_text.h:186
double GetTextAngle() const
Definition: eda_text.h:177
#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:143
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:204
bool IsVisible() const
Definition: eda_text.h:189
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 555 of file sch_legacy_plugin.cpp.

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

Definition at line 551 of file sch_legacy_plugin.cpp.

551 { m_isModified = aModified; }

Member Data Documentation

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 471 of file sch_legacy_plugin.cpp.

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

wxString SCH_LEGACY_PLUGIN_CACHE::m_fileName
private

Definition at line 469 of file sch_legacy_plugin.cpp.

Referenced by IsFile(), and loadPart().

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 474 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

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

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

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

Definition at line 475 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 476 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 519 of file sch_legacy_plugin.cpp.


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