Commit dc9122c5 authored by Dick Hollenbeck's avatar Dick Hollenbeck

remove "~" from empty *.lib component fields, replace with "", doctor old...

remove "~" from empty *.lib component fields, replace with "", doctor old *.lib fields to blank if that was the intention
parent c4c58e12
...@@ -581,7 +581,6 @@ LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert ...@@ -581,7 +581,6 @@ LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert
bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
{ {
size_t i;
LIB_FIELD& value = GetValueField(); LIB_FIELD& value = GetValueField();
// First line: it s a comment (component name for readers) // First line: it s a comment (component name for readers)
...@@ -590,6 +589,14 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -590,6 +589,14 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
// Save data // Save data
aFormatter.Print( 0, "DEF" ); aFormatter.Print( 0, "DEF" );
#if defined(DEBUG)
if( value.GetText() == wxT( "R" ) )
{
int breakhere = 1;
(void) breakhere;
}
#endif
if( value.IsVisible() ) if( value.IsVisible() )
{ {
aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) ); aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
...@@ -627,7 +634,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -627,7 +634,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
// may have their own save policy so there is a separate loop for them. // may have their own save policy so there is a separate loop for them.
// Empty fields are saved, because the user may have set visibility, // Empty fields are saved, because the user may have set visibility,
// size and orientation // size and orientation
for( i = 0; i < MANDATORY_FIELDS; ++i ) for( int i = 0; i < MANDATORY_FIELDS; ++i )
{ {
if( !fields[i].Save( aFormatter ) ) if( !fields[i].Save( aFormatter ) )
return false; return false;
...@@ -638,7 +645,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -638,7 +645,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
int fieldId = MANDATORY_FIELDS; // really wish this would go away. int fieldId = MANDATORY_FIELDS; // really wish this would go away.
for( i = MANDATORY_FIELDS; i < fields.size(); ++i ) for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
{ {
// There is no need to save empty fields, i.e. no reason to preserve field // There is no need to save empty fields, i.e. no reason to preserve field
// names now that fields names come in dynamically through the template // names now that fields names come in dynamically through the template
...@@ -659,7 +666,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -659,7 +666,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
{ {
aFormatter.Print( 0, "ALIAS" ); aFormatter.Print( 0, "ALIAS" );
for( i = 1; i < m_aliases.size(); i++ ) for( unsigned i = 1; i < m_aliases.size(); i++ )
{ {
aFormatter.Print( 0, " %s", TO_UTF8( m_aliases[i]->GetName() ) ); aFormatter.Print( 0, " %s", TO_UTF8( m_aliases[i]->GetName() ) );
} }
...@@ -672,7 +679,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -672,7 +679,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
{ {
aFormatter.Print( 0, "$FPLIST\n" ); aFormatter.Print( 0, "$FPLIST\n" );
for( i = 0; i < m_FootprintList.GetCount(); i++ ) for( unsigned i = 0; i < m_FootprintList.GetCount(); i++ )
{ {
aFormatter.Print( 0, " %s\n", TO_UTF8( m_FootprintList[i] ) ); aFormatter.Print( 0, " %s\n", TO_UTF8( m_FootprintList[i] ) );
} }
...@@ -715,7 +722,7 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) ...@@ -715,7 +722,7 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
char* prefix = NULL; char* prefix = NULL;
char* line; char* line;
bool Res; bool result;
wxString Msg; wxString Msg;
line = aLineReader.Line(); line = aLineReader.Line();
...@@ -749,10 +756,8 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) ...@@ -749,10 +756,8 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ), aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ),
aLineReader.LineNumber() ); aLineReader.LineNumber() );
while( aLineReader.ReadLine() ) while( (line = aLineReader.ReadLine()) != NULL )
{ {
line = aLineReader.Line();
p = strtok( line, " \t\n" ); p = strtok( line, " \t\n" );
if( stricmp( p, "ENDDEF" ) == 0 ) if( stricmp( p, "ENDDEF" ) == 0 )
...@@ -808,36 +813,34 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) ...@@ -808,36 +813,34 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
m_options = ENTRY_POWER; m_options = ENTRY_POWER;
// Read next lines, until "ENDDEF" is found // Read next lines, until "ENDDEF" is found
while( aLineReader.ReadLine() ) while( ( line = aLineReader.ReadLine() ) != NULL )
{ {
line = aLineReader.Line();
p = strtok( line, " \t\r\n" ); p = strtok( line, " \t\r\n" );
// This is the error flag ( if an error occurs, Res = false) // This is the error flag ( if an error occurs, result = false)
Res = true; result = true;
if( *line == '#' ) // a comment if( *line == '#' ) // a comment
continue; continue;
if( (*line == 'T') && (*(line + 1) == 'i') ) if( line[0] == 'T' && line[1] == 'i' )
Res = LoadDateAndTime( aLineReader ); result = LoadDateAndTime( aLineReader );
else if( *line == 'F' ) else if( *line == 'F' )
Res = LoadField( aLineReader, Msg ); result = LoadField( aLineReader, Msg );
else if( strcmp( p, "ENDDEF" ) == 0 ) // End of component description else if( strcmp( p, "ENDDEF" ) == 0 ) // End of component description
break; goto ok;
else if( strcmp( p, "DRAW" ) == 0 ) else if( strcmp( p, "DRAW" ) == 0 )
Res = LoadDrawEntries( aLineReader, Msg ); result = LoadDrawEntries( aLineReader, Msg );
else if( strncmp( p, "ALIAS", 5 ) == 0 ) else if( strncmp( p, "ALIAS", 5 ) == 0 )
{ {
p = strtok( NULL, "\r\n" ); p = strtok( NULL, "\r\n" );
Res = LoadAliases( p, aErrorMsg ); result = LoadAliases( p, aErrorMsg );
} }
else if( strncmp( p, "$FPLIST", 5 ) == 0 ) else if( strncmp( p, "$FPLIST", 5 ) == 0 )
Res = LoadFootprints( aLineReader, Msg ); result = LoadFootprints( aLineReader, Msg );
// End line or block analysis: test for an error // End line or block analysis: test for an error
if( !Res ) if( !result )
{ {
if( Msg.IsEmpty() ) if( Msg.IsEmpty() )
aErrorMsg.Printf( wxT( "error occurred at line %d " ), aLineReader.LineNumber() ); aErrorMsg.Printf( wxT( "error occurred at line %d " ), aLineReader.LineNumber() );
...@@ -849,6 +852,9 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) ...@@ -849,6 +852,9 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
} }
} }
return false;
ok:
// If we are here, this part is O.k. - put it in: // If we are here, this part is O.k. - put it in:
drawings.sort(); drawings.sort();
...@@ -863,14 +869,12 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM ...@@ -863,14 +869,12 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM
while( true ) while( true )
{ {
if( !aLineReader.ReadLine() ) if( !( line = aLineReader.ReadLine() ) )
{ {
aErrorMsg = wxT( "file ended prematurely loading component draw element" ); aErrorMsg = wxT( "file ended prematurely loading component draw element" );
return false; return false;
} }
line = aLineReader.Line();
if( strncmp( line, "ENDDRAW", 7 ) == 0 ) if( strncmp( line, "ENDDRAW", 7 ) == 0 )
break; break;
...@@ -925,8 +929,8 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM ...@@ -925,8 +929,8 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM
{ {
if( !aLineReader.ReadLine() ) if( !aLineReader.ReadLine() )
{ {
aErrorMsg = wxT( "file ended prematurely while attempting \ aErrorMsg = wxT( "file ended prematurely while attempting "
to flush to end of drawing section." ); "to flush to end of drawing section." );
return false; return false;
} }
} while( strncmp( line, "ENDDRAW", 7 ) != 0 ); } while( strncmp( line, "ENDDRAW", 7 ) != 0 );
...@@ -999,13 +1003,12 @@ bool LIB_COMPONENT::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMs ...@@ -999,13 +1003,12 @@ bool LIB_COMPONENT::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMs
while( true ) while( true )
{ {
if( !aLineReader.ReadLine() ) if( !( line = aLineReader.ReadLine() ) )
{ {
aErrorMsg = wxT( "file ended prematurely while loading footprints" ); aErrorMsg = wxT( "file ended prematurely while loading footprints" );
return false; return false;
} }
line = aLineReader.Line();
p = strtok( line, " \t\r\n" ); p = strtok( line, " \t\r\n" );
if( stricmp( p, "$ENDFPLIST" ) == 0 ) if( stricmp( p, "$ENDFPLIST" ) == 0 )
...@@ -1459,7 +1462,7 @@ LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, ...@@ -1459,7 +1462,7 @@ LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
item = LocateDrawItem( aUnit, aConvert, aType, aPoint ); item = LocateDrawItem( aUnit, aConvert, aType, aPoint );
//Restore matrix // Restore matrix
DefaultTransform = transform; DefaultTransform = transform;
return item; return item;
......
...@@ -76,20 +76,7 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void ) ...@@ -76,20 +76,7 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void )
return cmpname; return cmpname;
} }
/*
* Function SelectComponentFromLib
* Calls the library viewer to select component to import into schematic.
* if the library viewer is currently running, it is closed and reopened
* in modal mode.
* param aLibname = the lib name or an empty string.
* if aLibname is empty, the full list of libraries is used
* param aList = list of previously loaded components
* param aUseLibBrowser = bool to call the library viewer to select the component
* param aUnit = a point to int to return the selected unit (if any)
* param aConvert = a point to int to return the selected De Morgan shape (if any)
*
* return the component name
*/
wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
wxArrayString& aHistoryList, wxArrayString& aHistoryList,
bool aUseLibBrowser, bool aUseLibBrowser,
...@@ -205,11 +192,6 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, ...@@ -205,11 +192,6 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
} }
/*
* load from a library and place a component
* if libname != "", search in lib "libname"
* else search in all loaded libs
*/
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
const wxString& aLibname, const wxString& aLibname,
wxArrayString& aHistoryList, wxArrayString& aHistoryList,
...@@ -260,8 +242,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, ...@@ -260,8 +242,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
component->GetField( VALUE )->SetText( Name ); component->GetField( VALUE )->SetText( Name );
MSG_PANEL_ITEMS items; MSG_PANEL_ITEMS items;
component->SetCurrentSheetPath( &GetCurrentSheet() ); component->SetCurrentSheetPath( &GetCurrentSheet() );
component->GetMsgPanelInfo( items ); component->GetMsgPanelInfo( items );
SetMsgPanel( items ); SetMsgPanel( items );
component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
component->SetFlags( IS_NEW ); component->SetFlags( IS_NEW );
...@@ -271,9 +255,6 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, ...@@ -271,9 +255,6 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
} }
/*
* Routine to rotate and mirror a component.
*/
void SCH_EDIT_FRAME::OrientComponent( COMPONENT_ORIENTATION_T aOrientation ) void SCH_EDIT_FRAME::OrientComponent( COMPONENT_ORIENTATION_T aOrientation )
{ {
SCH_SCREEN* screen = GetScreen(); SCH_SCREEN* screen = GetScreen();
......
...@@ -100,8 +100,14 @@ bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -100,8 +100,14 @@ bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter )
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP ) else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
vjustify = 'T'; vjustify = 'T';
/* Dick 24-May-2013:
What the hell is this?. There was no comment here.
Hell no. You don't want this in the *.lib files, it is crap. Fields get read
back in and they have a tilda in them.
if( text.IsEmpty() ) if( text.IsEmpty() )
text = wxT( "~" ); text = wxT( "~" );
*/
aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c", aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
m_id, m_id,
...@@ -131,12 +137,14 @@ bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -131,12 +137,14 @@ bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter )
bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg ) bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg )
{ {
int cnt; int cnt;
char textOrient; char textOrient;
char textVisible; char textVisible;
char textHJustify; char textHJustify;
char textVJustify[256]; char textVJustify[256];
char* line = (char*) aLineReader;
char* line = (char*) aLineReader;
char* limit = line + aLineReader.Length();
if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 ) if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 )
{ {
...@@ -144,23 +152,20 @@ bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg ) ...@@ -144,23 +152,20 @@ bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg )
return false; return false;
} }
/* Search the beginning of the data. */ // Caller did a strtok(), which inserts a nul, so next few bytes are ugly:
while( *line != 0 ) // digit(s), a nul, some whitespace, then a double quote.
line++; while( line < limit && *line != '"' )
while( *line == 0 )
line++; line++;
while( *line && (*line != '"') ) if( line == limit )
line++;
if( *line == 0 )
return false; return false;
line += ReadDelimitedText( &m_Text, line ); line += ReadDelimitedText( &m_Text, line );
if( *line == 0 ) // Doctor the *.lib file field which has a "~" in blank fields. New saves will
return false; // not save like this, and eventually these two lines can be removed.
if( m_Text.size()==1 && m_Text[0]==wxChar( '~' ) )
m_Text.clear();
memset( textVJustify, 0, sizeof( textVJustify ) ); memset( textVJustify, 0, sizeof( textVJustify ) );
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
* 0 = REFERENCE * 0 = REFERENCE
* 1 = VALUE * 1 = VALUE
* 2 = FOOTPRINT (default Footprint) * 2 = FOOTPRINT (default Footprint)
* 3 = DOCUMENTATION (user doc link) * 3 = DATASHEET (user doc link)
* *
* others = free fields * others = free fields
* </p> * </p>
......
...@@ -975,7 +975,12 @@ public: ...@@ -975,7 +975,12 @@ public:
private: private:
// Component /**
* Function Load_Component
* loads from a library and places a component.
* if libname != "", search in lib "libname"
* else search in all loaded libs
*/
SCH_COMPONENT* Load_Component( wxDC* DC, SCH_COMPONENT* Load_Component( wxDC* DC,
const wxString& libname, const wxString& libname,
wxArrayString& List, wxArrayString& List,
...@@ -990,6 +995,11 @@ private: ...@@ -990,6 +995,11 @@ private:
void EditComponent( SCH_COMPONENT* aComponent ); void EditComponent( SCH_COMPONENT* aComponent );
public: public:
/**
* Function OrientComponent
* rotates and mirrors a component.
*/
void OrientComponent( COMPONENT_ORIENTATION_T aOrientation = CMP_NORMAL ); void OrientComponent( COMPONENT_ORIENTATION_T aOrientation = CMP_NORMAL );
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment