Use output formatter to save component library files and objects.
This commit is contained in:
parent
fcb482df41
commit
3541335a08
|
@ -527,52 +527,45 @@ LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert
|
|||
}
|
||||
|
||||
|
||||
bool LIB_COMPONENT::Save( FILE* aFile )
|
||||
bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
size_t i;
|
||||
LIB_FIELD& value = GetValueField();
|
||||
|
||||
/* First line: it s a comment (component name for readers) */
|
||||
if( fprintf( aFile, "#\n# %s\n#\n", TO_UTF8( value.m_Text ) ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.m_Text ) );
|
||||
|
||||
/* Save data */
|
||||
if( fprintf( aFile, "DEF" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "DEF" );
|
||||
|
||||
if( value.IsVisible() )
|
||||
{
|
||||
if( fprintf( aFile, " %s", TO_UTF8( value.m_Text ) ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %s", TO_UTF8( value.m_Text ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fprintf( aFile, " ~%s", TO_UTF8( value.m_Text ) ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " ~%s", TO_UTF8( value.m_Text ) );
|
||||
}
|
||||
|
||||
LIB_FIELD& reference = GetReferenceField();
|
||||
|
||||
if( !reference.m_Text.IsEmpty() )
|
||||
{
|
||||
if( fprintf( aFile, " %s", TO_UTF8( reference.m_Text ) ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %s", TO_UTF8( reference.m_Text ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fprintf( aFile, " ~" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " ~" );
|
||||
}
|
||||
|
||||
if( fprintf( aFile, " %d %d %c %c %d %c %c\n",
|
||||
0, m_pinNameOffset,
|
||||
m_showPinNumbers ? 'Y' : 'N',
|
||||
m_showPinNames ? 'Y' : 'N',
|
||||
m_unitCount, m_unitsLocked ? 'L' : 'F',
|
||||
m_options == ENTRY_POWER ? 'P' : 'N' ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
|
||||
0, m_pinNameOffset,
|
||||
m_showPinNumbers ? 'Y' : 'N',
|
||||
m_showPinNames ? 'Y' : 'N',
|
||||
m_unitCount, m_unitsLocked ? 'L' : 'F',
|
||||
m_options == ENTRY_POWER ? 'P' : 'N' );
|
||||
|
||||
if( !SaveDateAndTime( aFile ) )
|
||||
if( !SaveDateAndTime( aFormatter ) )
|
||||
return false;
|
||||
|
||||
LIB_FIELDS fields;
|
||||
|
@ -584,7 +577,7 @@ bool LIB_COMPONENT::Save( FILE* aFile )
|
|||
{
|
||||
if( !fields[i].m_Text.IsEmpty() )
|
||||
{
|
||||
if( !fields[i].Save( aFile ) )
|
||||
if( !fields[i].Save( aFormatter ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -603,7 +596,7 @@ bool LIB_COMPONENT::Save( FILE* aFile )
|
|||
{
|
||||
fields[i].SetId( fieldId++ );
|
||||
|
||||
if( !fields[i].Save( aFile ) )
|
||||
if( !fields[i].Save( aFormatter ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -613,33 +606,27 @@ bool LIB_COMPONENT::Save( FILE* aFile )
|
|||
// alias does not get added to the alias list.
|
||||
if( m_aliases.size() > 1 )
|
||||
{
|
||||
if( fprintf( aFile, "ALIAS" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "ALIAS" );
|
||||
|
||||
for( i = 1; i < m_aliases.size(); i++ )
|
||||
{
|
||||
if( fprintf( aFile, " %s", TO_UTF8( m_aliases[i]->GetName() ) ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %s", TO_UTF8( m_aliases[i]->GetName() ) );
|
||||
}
|
||||
|
||||
if( fprintf( aFile, "\n" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "\n" );
|
||||
}
|
||||
|
||||
/* Write the footprint filter list */
|
||||
if( m_FootprintList.GetCount() != 0 )
|
||||
{
|
||||
if( fprintf( aFile, "$FPLIST\n" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "$FPLIST\n" );
|
||||
|
||||
for( i = 0; i < m_FootprintList.GetCount(); i++ )
|
||||
{
|
||||
if( fprintf( aFile, " %s\n", TO_UTF8( m_FootprintList[i] ) ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %s\n", TO_UTF8( m_FootprintList[i] ) );
|
||||
}
|
||||
|
||||
if( fprintf( aFile, "$ENDFPLIST\n" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "$ENDFPLIST\n" );
|
||||
}
|
||||
|
||||
/* Save graphics items (including pins) */
|
||||
|
@ -649,24 +636,21 @@ bool LIB_COMPONENT::Save( FILE* aFile )
|
|||
* when a file editing "by hand" is made */
|
||||
drawings.sort();
|
||||
|
||||
if( fprintf( aFile, "DRAW\n" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "DRAW\n" );
|
||||
|
||||
BOOST_FOREACH( LIB_ITEM& item, drawings )
|
||||
{
|
||||
if( item.Type() == LIB_FIELD_T )
|
||||
continue;
|
||||
|
||||
if( !item.Save( aFile ) )
|
||||
if( !item.Save( aFormatter ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( fprintf( aFile, "ENDDRAW\n" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "ENDDRAW\n" );
|
||||
}
|
||||
|
||||
if( fprintf( aFile, "ENDDEF\n" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "ENDDEF\n" );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1143,7 +1127,7 @@ LIB_FIELD& LIB_COMPONENT::GetReferenceField()
|
|||
}
|
||||
|
||||
|
||||
bool LIB_COMPONENT::SaveDateAndTime( FILE* aFile )
|
||||
bool LIB_COMPONENT::SaveDateAndTime( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
int year, mon, day, hour, min, sec;
|
||||
|
||||
|
@ -1157,12 +1141,12 @@ bool LIB_COMPONENT::SaveDateAndTime( FILE* aFile )
|
|||
mon = ( m_dateModified >> 22 ) & 15;
|
||||
year = ( m_dateModified >> 26 ) + 1990;
|
||||
|
||||
if ( fprintf( aFile, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool LIB_COMPONENT::LoadDateAndTime( char* aLine )
|
||||
{
|
||||
int year, mon, day, hour, min, sec;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
|
||||
class LINE_READER;
|
||||
class OUTPUTFORMATTER;
|
||||
class CMP_LIBRARY;
|
||||
class LIB_ALIAS;
|
||||
class LIB_COMPONENT;
|
||||
|
@ -290,20 +291,23 @@ public:
|
|||
* write the date and time of component to \a aFile in the format:
|
||||
* "Ti yy/mm/jj hh:mm:ss"
|
||||
*
|
||||
* @param aFile A point to a FILE object containing the file to write to.
|
||||
* @return True if the date and time were successfully written to \a aFile.
|
||||
* @param aFormatter A reference to an OUTPUT_FORMATER object containing the
|
||||
* output format to write to.
|
||||
* @return True if the date and time were successfully written to \a aFormatter.
|
||||
*/
|
||||
bool SaveDateAndTime( FILE* aFile );
|
||||
bool SaveDateAndTime( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
bool LoadDateAndTime( char* aLine );
|
||||
|
||||
/**
|
||||
* Write the data structures out to a FILE in "*.lib" format.
|
||||
* Function Save
|
||||
* writes the data structures out to \a aFormatter in the component library "*.lib"
|
||||
* format.
|
||||
*
|
||||
* @param aFile - The FILE to write to.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
bool Save( FILE* aFile );
|
||||
bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
/**
|
||||
* Load component definition from \a aReader.
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/regex.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
|
||||
static const wxChar* duplicate_name_msg =
|
||||
|
@ -69,6 +70,7 @@ bool operator<( const CMP_LIBRARY& aItem1, const CMP_LIBRARY& aItem2 )
|
|||
/* The cache library always is sorted to the end of the library list. */
|
||||
if( aItem2.IsCache() )
|
||||
return true;
|
||||
|
||||
if( aItem1.IsCache() )
|
||||
return false;
|
||||
|
||||
|
@ -670,7 +672,6 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg )
|
|||
|
||||
bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
|
||||
{
|
||||
FILE* libfile;
|
||||
wxString msg;
|
||||
wxFileName libFileName = aFullFileName;
|
||||
wxFileName backupFileName = aFullFileName;
|
||||
|
@ -690,9 +691,9 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
|
|||
}
|
||||
}
|
||||
|
||||
libfile = wxFopen( libFileName.GetFullPath(), wxT( "wt" ) );
|
||||
wxFFileOutputStream os( libFileName.GetFullPath(), wxT( "wt" ) );
|
||||
|
||||
if( libfile == NULL )
|
||||
if( !os.IsOk() )
|
||||
{
|
||||
libFileName.MakeAbsolute();
|
||||
msg = wxT( "Failed to create component library file " ) + libFileName.GetFullPath();
|
||||
|
@ -700,31 +701,34 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
|
|||
return false;
|
||||
}
|
||||
|
||||
isModified = false;
|
||||
STREAM_OUTPUTFORMATTER formatter( os );
|
||||
|
||||
timeStamp = GetTimeStamp();
|
||||
|
||||
if( !SaveHeader( libfile ) )
|
||||
if( isModified )
|
||||
{
|
||||
fclose( libfile );
|
||||
return false;
|
||||
timeStamp = GetTimeStamp();
|
||||
isModified = false;
|
||||
}
|
||||
|
||||
bool success = true;
|
||||
|
||||
for( LIB_ALIAS_MAP::iterator it=aliases.begin(); it!=aliases.end(); it++ )
|
||||
try
|
||||
{
|
||||
if( !(*it).second->IsRoot() )
|
||||
continue;
|
||||
SaveHeader( formatter );
|
||||
|
||||
if ( !(*it).second->GetComponent()->Save( libfile ) )
|
||||
success = false;
|
||||
for( LIB_ALIAS_MAP::iterator it=aliases.begin(); it!=aliases.end(); it++ )
|
||||
{
|
||||
if( !(*it).second->IsRoot() )
|
||||
continue;
|
||||
|
||||
(*it).second->GetComponent()->Save( formatter );
|
||||
}
|
||||
|
||||
formatter.Print( 0, "#\n#End Library\n" );
|
||||
}
|
||||
|
||||
if( fprintf( libfile, "#\n#End Library\n" ) < 0 )
|
||||
catch( IO_ERROR ioe )
|
||||
{
|
||||
success = false;
|
||||
|
||||
fclose( libfile );
|
||||
}
|
||||
|
||||
if( USE_OLD_DOC_FILE_FORMAT( versionMajor, versionMinor ) && aOldDocFormat )
|
||||
success = SaveDocFile( aFullFileName );
|
||||
|
@ -793,28 +797,25 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
|
|||
}
|
||||
|
||||
|
||||
bool CMP_LIBRARY::SaveHeader( FILE* aFile )
|
||||
bool CMP_LIBRARY::SaveHeader( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
char BufLine[1024];
|
||||
bool succes = true;
|
||||
|
||||
DateAndTime( BufLine );
|
||||
|
||||
if( fprintf( aFile, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
|
||||
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 )
|
||||
succes = false;
|
||||
aFormatter.Print( 0, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
|
||||
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine );
|
||||
|
||||
if( fprintf( aFile, "#encoding utf-8\n") < 0 )
|
||||
succes = false;
|
||||
aFormatter.Print( 0, "#encoding utf-8\n");
|
||||
|
||||
#if 0
|
||||
if( ( fprintf( aFile, "$HEADER\n" ) < 0 )
|
||||
|| ( fprintf( aFile, "TimeStamp %8.8lX\n", m_TimeStamp ) < 0 )
|
||||
|| ( fprintf( aFile, "Parts %d\n", aliases.size() ) != 2 )
|
||||
|| ( fprintf( aFile, "$ENDHEADER\n" ) != 1 ) )
|
||||
succes = false;
|
||||
aFormatter.Print( 0, "$HEADER\n" );
|
||||
aFormatter.Print( 0, "TimeStamp %8.8lX\n", m_TimeStamp );
|
||||
aFormatter.Print( 0, "Parts %d\n", aliases.size() );
|
||||
aFormatter.Print( 0, "$ENDHEADER\n" ) != 1 );
|
||||
#endif
|
||||
return succes;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
|
||||
class LINE_READER;
|
||||
class OUTPUTFORMATTER;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -130,7 +131,7 @@ public:
|
|||
bool LoadDocs( wxString& aErrorMsg );
|
||||
|
||||
private:
|
||||
bool SaveHeader( FILE* aFile );
|
||||
bool SaveHeader( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
bool LoadHeader( LINE_READER& aLineReader );
|
||||
void LoadAliases( LIB_COMPONENT* aComponent );
|
||||
|
|
|
@ -105,7 +105,7 @@ LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_ITEM( aArc )
|
|||
}
|
||||
|
||||
|
||||
bool LIB_ARC::Save( FILE* aFile )
|
||||
bool LIB_ARC::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
int x1 = m_t1;
|
||||
|
||||
|
@ -117,11 +117,10 @@ bool LIB_ARC::Save( FILE* aFile )
|
|||
if( x2 > 1800 )
|
||||
x2 -= 3600;
|
||||
|
||||
if( fprintf( aFile, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
|
||||
m_Pos.x, m_Pos.y, m_Radius, x1, x2, m_Unit, m_Convert, m_Width,
|
||||
fill_tab[m_Fill], m_ArcStart.x, m_ArcStart.y, m_ArcEnd.x,
|
||||
m_ArcEnd.y ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
|
||||
m_Pos.x, m_Pos.y, m_Radius, x1, x2, m_Unit, m_Convert, m_Width,
|
||||
fill_tab[m_Fill], m_ArcStart.x, m_ArcStart.y, m_ArcEnd.x,
|
||||
m_ArcEnd.y );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -30,12 +30,10 @@
|
|||
#ifndef _LIB_ARC_H_
|
||||
#define _LIB_ARC_H_
|
||||
|
||||
|
||||
#include "lib_draw_item.h"
|
||||
|
||||
|
||||
class TRANSFORM;
|
||||
class LINE_READER;
|
||||
|
||||
|
||||
class LIB_ARC : public LIB_ITEM
|
||||
|
@ -99,10 +97,11 @@ public:
|
|||
/**
|
||||
* Save arc object to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile The FILE to write to.
|
||||
* @return - True if success writing else false.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* arc to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
|
||||
|
||||
|
|
|
@ -62,21 +62,18 @@ LIB_BEZIER::LIB_BEZIER( const LIB_BEZIER& aBezier ) : LIB_ITEM( aBezier )
|
|||
}
|
||||
|
||||
|
||||
bool LIB_BEZIER::Save( FILE* aFile )
|
||||
bool LIB_BEZIER::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
int ccount = GetCornerCount();
|
||||
|
||||
if( fprintf( aFile, "B %d %d %d %d", ccount, m_Unit, m_Convert, m_Width ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "B %d %d %d %d", ccount, m_Unit, m_Convert, m_Width );
|
||||
|
||||
for( unsigned i = 0; i < GetCornerCount(); i++ )
|
||||
{
|
||||
if( fprintf( aFile, " %d %d", m_BezierPoints[i].x, m_BezierPoints[i].y ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %d %d", m_BezierPoints[i].x, m_BezierPoints[i].y );
|
||||
}
|
||||
|
||||
if( fprintf( aFile, " %c\n", fill_tab[m_Fill] ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %c\n", fill_tab[m_Fill] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -33,12 +33,10 @@
|
|||
#include "lib_draw_item.h"
|
||||
|
||||
|
||||
class LINE_READER;
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/* Graphic Body Item: Bezier Curve (set of lines) */
|
||||
/**************************************************/
|
||||
/**
|
||||
* Class LIB_BEZIER
|
||||
* defines bezier curve graphic body item.
|
||||
*/
|
||||
class LIB_BEZIER : public LIB_ITEM
|
||||
{
|
||||
int m_Width; // Line width
|
||||
|
@ -65,10 +63,11 @@ public:
|
|||
/**
|
||||
* Write bezier curve object out to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile - The FILE to write to.
|
||||
* @return true if success writing else false.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* bezier curve to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
|
||||
|
||||
|
|
|
@ -64,11 +64,10 @@ LIB_CIRCLE::LIB_CIRCLE( const LIB_CIRCLE& aCircle ) :
|
|||
}
|
||||
|
||||
|
||||
bool LIB_CIRCLE::Save( FILE* aFile )
|
||||
bool LIB_CIRCLE::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
if( fprintf( aFile, "C %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
||||
m_Radius, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
||||
m_Radius, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -33,9 +33,6 @@
|
|||
#include "lib_draw_item.h"
|
||||
|
||||
|
||||
class LINE_READER;
|
||||
|
||||
|
||||
class LIB_CIRCLE : public LIB_ITEM
|
||||
{
|
||||
int m_Radius;
|
||||
|
@ -69,10 +66,11 @@ public:
|
|||
/**
|
||||
* Write circle object to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile - The FILE to write to.
|
||||
* @return - true if success writing else false.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* circle to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
|
||||
class LINE_READER;
|
||||
class OUTPUTFORMATTER;
|
||||
class LIB_COMPONENT;
|
||||
class PLOTTER;
|
||||
class LIB_ITEM;
|
||||
|
@ -213,12 +214,15 @@ public:
|
|||
virtual int GetPenSize() const = 0;
|
||||
|
||||
/**
|
||||
* Write draw item object to \a aFile in "*.lib" format.
|
||||
* Function Save
|
||||
* writes draw item object to \a aFormatter in component library "*.lib" format.
|
||||
*
|
||||
* @param aFile - The file to write to.
|
||||
* @return - true if success writing else false.
|
||||
* @param aFormatter A referenct to an #OUTPUTFORMATTER object to write the
|
||||
* component library item to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile ) = 0;
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter ) = 0;
|
||||
|
||||
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) = 0;
|
||||
|
||||
LIB_COMPONENT* GetParent()
|
||||
|
|
|
@ -97,7 +97,7 @@ void LIB_FIELD::Init( int id )
|
|||
}
|
||||
|
||||
|
||||
bool LIB_FIELD::Save( FILE* ExportFile )
|
||||
bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
int hjustify, vjustify;
|
||||
wxString text = m_Text;
|
||||
|
@ -119,16 +119,15 @@ bool LIB_FIELD::Save( FILE* ExportFile )
|
|||
if( text.IsEmpty() )
|
||||
text = wxT( "~" );
|
||||
|
||||
if( fprintf( ExportFile, "F%d %s %d %d %d %c %c %c %c%c%c",
|
||||
m_id,
|
||||
EscapedUTF8( text ).c_str(), // wraps in quotes
|
||||
m_Pos.x, m_Pos.y, m_Size.x,
|
||||
m_Orient == 0 ? 'H' : 'V',
|
||||
(m_Attributs & TEXT_NO_VISIBLE ) ? 'I' : 'V',
|
||||
hjustify, vjustify,
|
||||
m_Italic ? 'I' : 'N',
|
||||
m_Bold ? 'B' : 'N' ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
|
||||
m_id,
|
||||
EscapedUTF8( text ).c_str(), // wraps in quotes
|
||||
m_Pos.x, m_Pos.y, m_Size.x,
|
||||
m_Orient == 0 ? 'H' : 'V',
|
||||
(m_Attributs & TEXT_NO_VISIBLE ) ? 'I' : 'V',
|
||||
hjustify, vjustify,
|
||||
m_Italic ? 'I' : 'N',
|
||||
m_Bold ? 'B' : 'N' );
|
||||
|
||||
/* Save field name, if necessary
|
||||
* Field name is saved only if it is not the default name.
|
||||
|
@ -137,14 +136,10 @@ bool LIB_FIELD::Save( FILE* ExportFile )
|
|||
*/
|
||||
wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
|
||||
|
||||
if( m_id >= FIELD1 && !m_name.IsEmpty() && m_name != defName
|
||||
&& fprintf( ExportFile, " %s", EscapedUTF8( m_name ).c_str() ) < 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( m_id >= FIELD1 && !m_name.IsEmpty() && m_name != defName )
|
||||
aFormatter.Print( 0, " %s", EscapedUTF8( m_name ).c_str() );
|
||||
|
||||
if( fprintf( ExportFile, "\n" ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "\n" );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -137,10 +137,11 @@ public:
|
|||
/**
|
||||
* Writes field object out to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile The FILE to write to.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* field to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& errorMsg );
|
||||
|
||||
|
|
|
@ -568,7 +568,7 @@ bool LIB_PIN::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTran
|
|||
}
|
||||
|
||||
|
||||
bool LIB_PIN::Save( FILE* ExportFile )
|
||||
bool LIB_PIN::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
wxString StringPinNum;
|
||||
int Etype;
|
||||
|
@ -628,48 +628,49 @@ bool LIB_PIN::Save( FILE* ExportFile )
|
|||
|
||||
if( !m_name.IsEmpty() )
|
||||
{
|
||||
if( fprintf( ExportFile, "X %s", TO_UTF8( m_name ) ) < 0 )
|
||||
if( aFormatter.Print( 0, "X %s", TO_UTF8( m_name ) ) < 0 )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fprintf( ExportFile, "X ~" ) < 0 )
|
||||
if( aFormatter.Print( 0, "X ~" ) < 0 )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( fprintf( ExportFile, " %s %d %d %d %c %d %d %d %d %c",
|
||||
TO_UTF8( StringPinNum ), m_position.x, m_position.y,
|
||||
(int) m_length, (int) m_orientation, m_PinNumSize, m_PinNameSize,
|
||||
m_Unit, m_Convert, Etype ) < 0 )
|
||||
if( aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
|
||||
TO_UTF8( StringPinNum ), m_position.x, m_position.y,
|
||||
(int) m_length, (int) m_orientation, m_PinNumSize, m_PinNameSize,
|
||||
m_Unit, m_Convert, Etype ) < 0 )
|
||||
return false;
|
||||
|
||||
if( m_shape || !IsVisible() )
|
||||
{
|
||||
if( fprintf( ExportFile, " " ) < 0 )
|
||||
if( aFormatter.Print( 0, " " ) < 0 )
|
||||
return false;
|
||||
}
|
||||
if( !IsVisible() && fprintf( ExportFile, "N" ) < 0 )
|
||||
return false;
|
||||
if( m_shape & INVERT
|
||||
&& fprintf( ExportFile, "I" ) < 0 )
|
||||
return false;
|
||||
if( m_shape & CLOCK
|
||||
&& fprintf( ExportFile, "C" ) < 0 )
|
||||
return false;
|
||||
if( m_shape & LOWLEVEL_IN
|
||||
&& fprintf( ExportFile, "L" ) < 0 )
|
||||
return false;
|
||||
if( m_shape & LOWLEVEL_OUT
|
||||
&& fprintf( ExportFile, "V" ) < 0 )
|
||||
return false;
|
||||
if( m_shape & CLOCK_FALL
|
||||
&& fprintf( ExportFile, "F" ) < 0 )
|
||||
return false;
|
||||
if( m_shape & NONLOGIC
|
||||
&& fprintf( ExportFile, "X" ) < 0 )
|
||||
|
||||
if( !IsVisible() && aFormatter.Print( 0, "N" ) < 0 )
|
||||
return false;
|
||||
|
||||
if( fprintf( ExportFile, "\n" ) < 0 )
|
||||
if( m_shape & INVERT && aFormatter.Print( 0, "I" ) < 0 )
|
||||
return false;
|
||||
|
||||
if( m_shape & CLOCK && aFormatter.Print( 0, "C" ) < 0 )
|
||||
return false;
|
||||
|
||||
if( m_shape & LOWLEVEL_IN && aFormatter.Print( 0, "L" ) < 0 )
|
||||
return false;
|
||||
|
||||
if( m_shape & LOWLEVEL_OUT && aFormatter.Print( 0, "V" ) < 0 )
|
||||
return false;
|
||||
|
||||
if( m_shape & CLOCK_FALL && aFormatter.Print( 0, "F" ) < 0 )
|
||||
return false;
|
||||
|
||||
if( m_shape & NONLOGIC && aFormatter.Print( 0, "X" ) < 0 )
|
||||
return false;
|
||||
|
||||
if( aFormatter.Print( 0, "\n" ) < 0 )
|
||||
return false;
|
||||
|
||||
m_Flags &= ~IS_CHANGED;
|
||||
|
|
|
@ -32,9 +32,6 @@
|
|||
|
||||
#include "lib_draw_item.h"
|
||||
|
||||
class SCH_COMPONENT;
|
||||
class LINE_READER;
|
||||
|
||||
|
||||
#define TARGET_PIN_RADIUS 12 /* Circle diameter drawn at the active end of pins */
|
||||
|
||||
|
@ -153,10 +150,11 @@ public:
|
|||
/**
|
||||
* Write pin object to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile The FILE to write to.
|
||||
* @return - true if success writing else false.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* pin to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
|
||||
|
||||
|
|
|
@ -62,21 +62,18 @@ LIB_POLYLINE::LIB_POLYLINE( const LIB_POLYLINE& polyline ) :
|
|||
}
|
||||
|
||||
|
||||
bool LIB_POLYLINE::Save( FILE* aFile )
|
||||
bool LIB_POLYLINE::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
int ccount = GetCornerCount();
|
||||
|
||||
if( fprintf( aFile, "P %d %d %d %d", ccount, m_Unit, m_Convert, m_Width ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "P %d %d %d %d", ccount, m_Unit, m_Convert, m_Width );
|
||||
|
||||
for( unsigned i = 0; i < GetCornerCount(); i++ )
|
||||
{
|
||||
if( fprintf( aFile, " %d %d", m_PolyPoints[i].x, m_PolyPoints[i].y ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %d %d", m_PolyPoints[i].x, m_PolyPoints[i].y );
|
||||
}
|
||||
|
||||
if( fprintf( aFile, " %c\n", fill_tab[m_Fill] ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %c\n", fill_tab[m_Fill] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
#include "lib_draw_item.h"
|
||||
|
||||
class LINE_READER;
|
||||
|
||||
|
||||
class LIB_POLYLINE : public LIB_ITEM
|
||||
{
|
||||
|
@ -69,10 +67,11 @@ public:
|
|||
/**
|
||||
* Write polyline object out to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile - The FILE to write to.
|
||||
* @return - true if success writing else false.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* polyline to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
|
||||
|
||||
|
|
|
@ -65,11 +65,10 @@ LIB_RECTANGLE::LIB_RECTANGLE( const LIB_RECTANGLE& aRect ) :
|
|||
}
|
||||
|
||||
|
||||
bool LIB_RECTANGLE::Save( FILE* aFile )
|
||||
bool LIB_RECTANGLE::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
if( fprintf( aFile, "S %d %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
||||
m_End.x, m_End.y, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
|
||||
m_End.x, m_End.y, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -33,9 +33,6 @@
|
|||
#include "lib_draw_item.h"
|
||||
|
||||
|
||||
class LINE_READER;
|
||||
|
||||
|
||||
class LIB_RECTANGLE : public LIB_ITEM
|
||||
{
|
||||
wxPoint m_End; // Rectangle end point.
|
||||
|
@ -74,10 +71,11 @@ public:
|
|||
/**
|
||||
* Write rectangle object out to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile - The FILE to write to.
|
||||
* @return - true if success writing else false.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* rectangle to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ LIB_TEXT::LIB_TEXT(LIB_COMPONENT * aParent) :
|
|||
}
|
||||
|
||||
|
||||
bool LIB_TEXT::Save( FILE* ExportFile )
|
||||
bool LIB_TEXT::Save( OUTPUTFORMATTER& aFormatter )
|
||||
{
|
||||
wxString text = m_Text;
|
||||
|
||||
|
@ -72,13 +72,10 @@ bool LIB_TEXT::Save( FILE* ExportFile )
|
|||
text.Replace( wxT( " " ), wxT( "~" ) );
|
||||
}
|
||||
|
||||
if( fprintf( ExportFile, "T %d %d %d %d %d %d %d %s ", m_Orient, m_Pos.x, m_Pos.y,
|
||||
m_Size.x, m_Attributs, m_Unit, m_Convert, TO_UTF8( text ) ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, "T %d %d %d %d %d %d %d %s ", m_Orient, m_Pos.x, m_Pos.y,
|
||||
m_Size.x, m_Attributs, m_Unit, m_Convert, TO_UTF8( text ) );
|
||||
|
||||
if( fprintf( ExportFile, " %s %d", m_Italic ? "Italic" : "Normal",
|
||||
( m_Bold > 0 ) ? 1 : 0 ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %s %d", m_Italic ? "Italic" : "Normal", ( m_Bold > 0 ) ? 1 : 0 );
|
||||
|
||||
char hjustify = 'C';
|
||||
|
||||
|
@ -94,8 +91,7 @@ bool LIB_TEXT::Save( FILE* ExportFile )
|
|||
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
|
||||
vjustify = 'T';
|
||||
|
||||
if( fprintf( ExportFile, " %c %c\n", hjustify, vjustify ) < 0 )
|
||||
return false;
|
||||
aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -33,15 +33,14 @@
|
|||
#include "lib_draw_item.h"
|
||||
|
||||
|
||||
class LINE_READER;
|
||||
|
||||
|
||||
/*********************************************/
|
||||
/* Graphic Body Item: Text */
|
||||
/* This is only a graphic text. */
|
||||
/* Fields like Ref , value... are not Text, */
|
||||
/* they are a separate class */
|
||||
/*********************************************/
|
||||
/**
|
||||
* Class LIB_TEXT
|
||||
* defines a component library graphical text item.
|
||||
* <p>
|
||||
* This is only a graphical text item. Field text like the reference designator,
|
||||
* component value, etc. are not LIB_TEXT items. See the #LIB_FIELD class for the
|
||||
* field item definition.
|
||||
*/
|
||||
class LIB_TEXT : public LIB_ITEM, public EDA_TEXT
|
||||
{
|
||||
wxString m_savedText; ///< Temporary storage for the string when edition.
|
||||
|
@ -86,10 +85,11 @@ public:
|
|||
/**
|
||||
* Write text object out to a FILE in "*.lib" format.
|
||||
*
|
||||
* @param aFile - The FILE to write to.
|
||||
* @return - true if success writing else false.
|
||||
* @param aFormatter A reference to an OUTPUTFORMATTER to write the component library
|
||||
* text to.
|
||||
* @return True if success writing else false.
|
||||
*/
|
||||
virtual bool Save( FILE* aFile );
|
||||
virtual bool Save( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
|
||||
|
||||
|
|
|
@ -1,3 +1,28 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
||||
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file symbedit.cpp
|
||||
* @brief Functions to load from and save to file component libraries and symbols.
|
||||
|
@ -11,6 +36,7 @@
|
|||
#include "kicad_string.h"
|
||||
#include "gestfich.h"
|
||||
#include "class_sch_screen.h"
|
||||
#include "richio.h"
|
||||
|
||||
#include "general.h"
|
||||
#include "protos.h"
|
||||
|
@ -18,7 +44,7 @@
|
|||
#include "class_library.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <wx/ffile.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
|
||||
void LIB_EDIT_FRAME::LoadOneSymbol()
|
||||
|
@ -82,10 +108,13 @@ void LIB_EDIT_FRAME::LoadOneSymbol()
|
|||
{
|
||||
if( item.Type() == LIB_FIELD_T )
|
||||
continue;
|
||||
|
||||
if( item.GetUnit() )
|
||||
item.SetUnit( m_unit );
|
||||
|
||||
if( item.GetConvert() )
|
||||
item.SetConvert( m_convert );
|
||||
|
||||
item.m_Flags = IS_NEW;
|
||||
item.m_Selected = IS_SELECTED;
|
||||
|
||||
|
@ -129,12 +158,11 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
|
|||
|
||||
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
||||
|
||||
wxFFile file( fn.GetFullPath(), wxT( "wt" ) );
|
||||
wxFile file( fn.GetFullPath(), wxFile::write );
|
||||
|
||||
if( !file.IsOpened() )
|
||||
{
|
||||
msg.Printf( _( "Unable to create file <%s>" ),
|
||||
GetChars( fn.GetFullPath() ) );
|
||||
msg.Printf( _( "Unable to create file <%s>" ), GetChars( fn.GetFullPath() ) );
|
||||
DisplayError( this, msg );
|
||||
return;
|
||||
}
|
||||
|
@ -142,6 +170,8 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
|
|||
msg.Printf( _( "Saving symbol in [%s]" ), GetChars( fn.GetPath() ) );
|
||||
SetStatusText( msg );
|
||||
|
||||
wxFileOutputStream os( file );
|
||||
STREAM_OUTPUTFORMATTER formatter( os );
|
||||
wxString line;
|
||||
|
||||
/* File header */
|
||||
|
@ -172,32 +202,39 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
|
|||
|
||||
line << wxT( "1 0 N\n" );
|
||||
|
||||
if( !file.Write( line )
|
||||
|| !m_component->GetReferenceField().Save( file.fp() )
|
||||
|| !m_component->GetValueField().Save( file.fp() )
|
||||
|| !file.Write( wxT( "DRAW\n" ) ) )
|
||||
return;
|
||||
|
||||
LIB_ITEMS& drawList = m_component->GetDrawItemList();
|
||||
|
||||
BOOST_FOREACH( LIB_ITEM& item, drawList )
|
||||
try
|
||||
{
|
||||
if( item.Type() == LIB_FIELD_T )
|
||||
continue;
|
||||
formatter.Print( 0, TO_UTF8( line ) );
|
||||
m_component->GetReferenceField().Save( formatter );
|
||||
m_component->GetValueField().Save( formatter );
|
||||
formatter.Print( 0, "DRAW\n" );
|
||||
|
||||
/* Don't save unused parts or alternate body styles. */
|
||||
if( m_unit && item.GetUnit() && ( item.GetUnit() != m_unit ) )
|
||||
continue;
|
||||
LIB_ITEMS& drawList = m_component->GetDrawItemList();
|
||||
|
||||
if( m_convert && item.GetConvert() && ( item.GetConvert() != m_convert ) )
|
||||
continue;
|
||||
BOOST_FOREACH( LIB_ITEM& item, drawList )
|
||||
{
|
||||
if( item.Type() == LIB_FIELD_T )
|
||||
continue;
|
||||
|
||||
if( !item.Save( file.fp() ) )
|
||||
return;
|
||||
/* Don't save unused parts or alternate body styles. */
|
||||
if( m_unit && item.GetUnit() && ( item.GetUnit() != m_unit ) )
|
||||
continue;
|
||||
|
||||
if( m_convert && item.GetConvert() && ( item.GetConvert() != m_convert ) )
|
||||
continue;
|
||||
|
||||
item.Save( formatter );
|
||||
}
|
||||
|
||||
formatter.Print( 0, "ENDDRAW\n" );
|
||||
formatter.Print( 0, "ENDDEF\n" );
|
||||
}
|
||||
catch( IO_ERROR ioe )
|
||||
{
|
||||
msg.Printf( _( "An error occurred attempting to save symbol file <%s>" ),
|
||||
GetChars( fn.GetFullPath() ) );
|
||||
DisplayError( this, msg );
|
||||
}
|
||||
|
||||
if( !file.Write( wxT( "ENDDRAW\n" ) ) || !file.Write( wxT( "ENDDEF\n" ) ) )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue