diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index c5b0e57ab6..3c06d62237 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -581,7 +581,6 @@ LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) { - size_t i; LIB_FIELD& value = GetValueField(); // First line: it s a comment (component name for readers) @@ -590,6 +589,14 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) // Save data aFormatter.Print( 0, "DEF" ); +#if defined(DEBUG) + if( value.GetText() == wxT( "R" ) ) + { + int breakhere = 1; + (void) breakhere; + } +#endif + if( value.IsVisible() ) { aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) ); @@ -627,7 +634,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) // 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, // size and orientation - for( i = 0; i < MANDATORY_FIELDS; ++i ) + for( int i = 0; i < MANDATORY_FIELDS; ++i ) { if( !fields[i].Save( aFormatter ) ) return false; @@ -638,7 +645,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) 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 // names now that fields names come in dynamically through the template @@ -659,7 +666,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) { 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() ) ); } @@ -672,7 +679,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) { 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] ) ); } @@ -715,7 +722,7 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) char* prefix = NULL; char* line; - bool Res; + bool result; wxString Msg; line = aLineReader.Line(); @@ -749,10 +756,8 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ), aLineReader.LineNumber() ); - while( aLineReader.ReadLine() ) + while( (line = aLineReader.ReadLine()) != NULL ) { - line = aLineReader.Line(); - p = strtok( line, " \t\n" ); if( stricmp( p, "ENDDEF" ) == 0 ) @@ -808,36 +813,34 @@ bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) m_options = ENTRY_POWER; // Read next lines, until "ENDDEF" is found - while( aLineReader.ReadLine() ) + while( ( line = aLineReader.ReadLine() ) != NULL ) { - line = aLineReader.Line(); - p = strtok( line, " \t\r\n" ); - // This is the error flag ( if an error occurs, Res = false) - Res = true; + // This is the error flag ( if an error occurs, result = false) + result = true; if( *line == '#' ) // a comment continue; - if( (*line == 'T') && (*(line + 1) == 'i') ) - Res = LoadDateAndTime( aLineReader ); + if( line[0] == 'T' && line[1] == 'i' ) + result = LoadDateAndTime( aLineReader ); else if( *line == 'F' ) - Res = LoadField( aLineReader, Msg ); + result = LoadField( aLineReader, Msg ); else if( strcmp( p, "ENDDEF" ) == 0 ) // End of component description - break; + goto ok; else if( strcmp( p, "DRAW" ) == 0 ) - Res = LoadDrawEntries( aLineReader, Msg ); + result = LoadDrawEntries( aLineReader, Msg ); else if( strncmp( p, "ALIAS", 5 ) == 0 ) { p = strtok( NULL, "\r\n" ); - Res = LoadAliases( p, aErrorMsg ); + result = LoadAliases( p, aErrorMsg ); } else if( strncmp( p, "$FPLIST", 5 ) == 0 ) - Res = LoadFootprints( aLineReader, Msg ); + result = LoadFootprints( aLineReader, Msg ); // End line or block analysis: test for an error - if( !Res ) + if( !result ) { if( Msg.IsEmpty() ) aErrorMsg.Printf( wxT( "error occurred at line %d " ), aLineReader.LineNumber() ); @@ -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: drawings.sort(); @@ -863,14 +869,12 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM while( true ) { - if( !aLineReader.ReadLine() ) + if( !( line = aLineReader.ReadLine() ) ) { aErrorMsg = wxT( "file ended prematurely loading component draw element" ); return false; } - line = aLineReader.Line(); - if( strncmp( line, "ENDDRAW", 7 ) == 0 ) break; @@ -925,8 +929,8 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM { if( !aLineReader.ReadLine() ) { - aErrorMsg = wxT( "file ended prematurely while attempting \ -to flush to end of drawing section." ); + aErrorMsg = wxT( "file ended prematurely while attempting " + "to flush to end of drawing section." ); return false; } } while( strncmp( line, "ENDDRAW", 7 ) != 0 ); @@ -999,13 +1003,12 @@ bool LIB_COMPONENT::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMs while( true ) { - if( !aLineReader.ReadLine() ) + if( !( line = aLineReader.ReadLine() ) ) { aErrorMsg = wxT( "file ended prematurely while loading footprints" ); return false; } - line = aLineReader.Line(); p = strtok( line, " \t\r\n" ); if( stricmp( p, "$ENDFPLIST" ) == 0 ) @@ -1459,7 +1462,7 @@ LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, item = LocateDrawItem( aUnit, aConvert, aType, aPoint ); - //Restore matrix + // Restore matrix DefaultTransform = transform; return item; diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 3f651f5cce..78ef00e207 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -76,20 +76,7 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void ) 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, wxArrayString& aHistoryList, bool aUseLibBrowser, @@ -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, const wxString& aLibname, wxArrayString& aHistoryList, @@ -260,8 +242,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, component->GetField( VALUE )->SetText( Name ); MSG_PANEL_ITEMS items; + component->SetCurrentSheetPath( &GetCurrentSheet() ); component->GetMsgPanelInfo( items ); + SetMsgPanel( items ); component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); component->SetFlags( IS_NEW ); @@ -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 ) { SCH_SCREEN* screen = GetScreen(); diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 052f805148..60a32cf419 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -100,8 +100,14 @@ bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter ) else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP ) 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() ) text = wxT( "~" ); + */ aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c", m_id, @@ -131,12 +137,14 @@ bool LIB_FIELD::Save( OUTPUTFORMATTER& aFormatter ) bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg ) { - int cnt; - char textOrient; - char textVisible; - char textHJustify; - char textVJustify[256]; - char* line = (char*) aLineReader; + int cnt; + char textOrient; + char textVisible; + char textHJustify; + char textVJustify[256]; + + char* line = (char*) aLineReader; + char* limit = line + aLineReader.Length(); if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 ) { @@ -144,23 +152,20 @@ bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg ) return false; } - /* Search the beginning of the data. */ - while( *line != 0 ) + // Caller did a strtok(), which inserts a nul, so next few bytes are ugly: + // digit(s), a nul, some whitespace, then a double quote. + while( line < limit && *line != '"' ) line++; - while( *line == 0 ) - line++; - - while( *line && (*line != '"') ) - line++; - - if( *line == 0 ) + if( line == limit ) return false; line += ReadDelimitedText( &m_Text, line ); - if( *line == 0 ) - return false; + // Doctor the *.lib file field which has a "~" in blank fields. New saves will + // 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 ) ); diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 2680ff1a82..1a99b1a7a2 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -47,7 +47,7 @@ * 0 = REFERENCE * 1 = VALUE * 2 = FOOTPRINT (default Footprint) - * 3 = DOCUMENTATION (user doc link) + * 3 = DATASHEET (user doc link) * * others = free fields *

diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index a0341f1caf..7f8eca6ce9 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -975,7 +975,12 @@ public: 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, const wxString& libname, wxArrayString& List, @@ -990,6 +995,11 @@ private: void EditComponent( SCH_COMPONENT* aComponent ); public: + + /** + * Function OrientComponent + * rotates and mirrors a component. + */ void OrientComponent( COMPONENT_ORIENTATION_T aOrientation = CMP_NORMAL ); private: