copyright and formatting

This commit is contained in:
Dick Hollenbeck 2013-05-24 16:30:27 -05:00
parent 8bafc54cdc
commit c4c58e1279
4 changed files with 71 additions and 85 deletions

View File

@ -623,7 +623,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
LIB_FIELDS fields; LIB_FIELDS fields;
GetFields( fields ); GetFields( fields );
// Fixed fields: // Mandatory fields:
// 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

View File

@ -1,6 +1,28 @@
/*******************************************************************************/
/* library editor: edition of fields of lib entries (components in libraries) */ /*
/*******************************************************************************/ * This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2011-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2007 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
*/
#include <algorithm> #include <algorithm>
@ -29,31 +51,29 @@ static int s_SelectedRow;
#define COLUMN_FIELD_NAME 0 #define COLUMN_FIELD_NAME 0
#define COLUMN_TEXT 1 #define COLUMN_TEXT 1
/*****************************************************************************************/
class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB : public DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB : public DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE
/*****************************************************************************************/
{ {
private:
LIB_EDIT_FRAME* m_parent;
LIB_COMPONENT* m_libEntry;
bool m_skipCopyFromPanel;
/// a copy of the edited component's LIB_FIELDs
std::vector <LIB_FIELD> m_FieldsBuf;
public: public:
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( LIB_EDIT_FRAME* aParent, LIB_COMPONENT* aLibEntry ); DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( LIB_EDIT_FRAME* aParent, LIB_COMPONENT* aLibEntry );
~DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB(); //~DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB() {}
private: private:
// Events handlers: // Events handlers:
void OnInitDialog( wxInitDialogEvent& event ); void OnInitDialog( wxInitDialogEvent& event );
void OnListItemDeselected( wxListEvent& event ); void OnListItemDeselected( wxListEvent& event );
void OnListItemSelected( wxListEvent& event ); void OnListItemSelected( wxListEvent& event );
void addFieldButtonHandler( wxCommandEvent& event ); void addFieldButtonHandler( wxCommandEvent& event );
/**
* Function deleteFieldButtonHandler
* deletes a field.
* MANDATORY_FIELDS cannot be deleted.
* If a field is empty, it is removed.
* if not empty, the text is removed.
*/
void deleteFieldButtonHandler( wxCommandEvent& event ); void deleteFieldButtonHandler( wxCommandEvent& event );
void moveUpButtonHandler( wxCommandEvent& event ); void moveUpButtonHandler( wxCommandEvent& event );
void OnCancelButtonClick( wxCommandEvent& event ); void OnCancelButtonClick( wxCommandEvent& event );
void OnOKButtonClick( wxCommandEvent& event ); void OnOKButtonClick( wxCommandEvent& event );
@ -102,6 +122,13 @@ private:
for( unsigned ii = MANDATORY_FIELDS; ii<m_FieldsBuf.size(); ii++ ) for( unsigned ii = MANDATORY_FIELDS; ii<m_FieldsBuf.size(); ii++ )
setRowItem( ii, m_FieldsBuf[ii] ); setRowItem( ii, m_FieldsBuf[ii] );
} }
LIB_EDIT_FRAME* m_parent;
LIB_COMPONENT* m_libEntry;
bool m_skipCopyFromPanel;
/// a copy of the edited component's LIB_FIELDs
std::vector <LIB_FIELD> m_FieldsBuf;
}; };
@ -126,12 +153,10 @@ void LIB_EDIT_FRAME::InstallFieldsEditorDialog( wxCommandEvent& event )
} }
/***********************************************************************/
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB(
LIB_EDIT_FRAME* aParent, LIB_EDIT_FRAME* aParent,
LIB_COMPONENT* aLibEntry ) : LIB_COMPONENT* aLibEntry ) :
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE( aParent ) DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE( aParent )
/***********************************************************************/
{ {
m_parent = aParent; m_parent = aParent;
m_libEntry = aLibEntry; m_libEntry = aLibEntry;
@ -141,16 +166,7 @@ DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB(
} }
/***********************************************************************/
DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::~DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB()
/***********************************************************************/
{
}
/**********************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnInitDialog( wxInitDialogEvent& event ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnInitDialog( wxInitDialogEvent& event )
/**********************************************************************************/
{ {
m_skipCopyFromPanel = false; m_skipCopyFromPanel = false;
wxListItem columnLabel; wxListItem columnLabel;
@ -174,9 +190,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnInitDialog( wxInitDialogEvent& event
} }
/**********************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnListItemDeselected( wxListEvent& event ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnListItemDeselected( wxListEvent& event )
/**********************************************************************************/
{ {
if( !m_skipCopyFromPanel ) if( !m_skipCopyFromPanel )
{ {
@ -186,9 +200,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnListItemDeselected( wxListEvent& even
} }
/**********************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnListItemSelected( wxListEvent& event ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnListItemSelected( wxListEvent& event )
/**********************************************************************************/
{ {
// remember the selected row, statically // remember the selected row, statically
s_SelectedRow = event.GetIndex(); s_SelectedRow = event.GetIndex();
@ -197,23 +209,19 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnListItemSelected( wxListEvent& event
} }
/***********************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnCancelButtonClick( wxCommandEvent& event ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnCancelButtonClick( wxCommandEvent& event )
/***********************************************************************************/
{ {
EndModal( 1 ); EndModal( 1 );
} }
/**********************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event )
/**********************************************************************************/
{ {
if( !copyPanelToSelectedField() ) if( !copyPanelToSelectedField() )
return; return;
// test if reference prefix is acceptable // test if reference prefix is acceptable
if( ! SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].GetText() ) ) if( !SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].GetText() ) )
{ {
DisplayError( NULL, _( "Illegal reference prefix. A reference must start by a letter" ) ); DisplayError( NULL, _( "Illegal reference prefix. A reference must start by a letter" ) );
return; return;
@ -230,16 +238,18 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event
if( m_libEntry->HasAlias( newvalue ) && !m_libEntry->GetAlias( newvalue )->IsRoot() ) if( m_libEntry->HasAlias( newvalue ) && !m_libEntry->GetAlias( newvalue )->IsRoot() )
{ {
wxString msg; wxString msg = wxString::Format(
msg.Printf( _( "A new name is entered for this component\n\ _( "A new name is entered for this component\n"
An alias %s already exists!\nCannot update this component" ), "An alias %s already exists!\n"
GetChars( newvalue ) ); "Cannot update this component" ),
GetChars( newvalue )
);
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
/* End unused code */ /* End unused code */
/* save old cmp in undo list */ // save old cmp in undo list
m_parent->SaveCopyInUndoList( m_libEntry, IS_CHANGED ); m_parent->SaveCopyInUndoList( m_libEntry, IS_CHANGED );
// delete any fields with no name or no value before we copy all of m_FieldsBuf // delete any fields with no name or no value before we copy all of m_FieldsBuf
@ -298,14 +308,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::addFieldButtonHandler( wxCommandEvent&
} }
/*****************************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEvent& event ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEvent& event )
/*****************************************************************************************/
/* Delete a field.
* MANDATORY_FIELDS cannot be deleted.
* If a field is empty, it is removed.
* if not empty, the text is removed.
*/
{ {
unsigned fieldNdx = getSelectedFieldNdx(); unsigned fieldNdx = getSelectedFieldNdx();
@ -342,9 +345,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEven
} }
/*************************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB:: moveUpButtonHandler( wxCommandEvent& event ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB:: moveUpButtonHandler( wxCommandEvent& event )
/*************************************************************************************/
{ {
unsigned fieldNdx = getSelectedFieldNdx(); unsigned fieldNdx = getSelectedFieldNdx();
@ -378,13 +379,11 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB:: moveUpButtonHandler( wxCommandEvent& e
} }
/****************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::setSelectedFieldNdx( int aFieldNdx ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::setSelectedFieldNdx( int aFieldNdx )
/****************************************************************************/
{ {
/* deselect old selection, but I think this is done by single selection flag within fieldListCtrl // deselect old selection, but I think this is done by single selection
* fieldListCtrl->SetItemState( s_SelectedRow, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); // flag within fieldListCtrl
*/ // fieldListCtrl->SetItemState( s_SelectedRow, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
if( aFieldNdx >= (int) m_FieldsBuf.size() ) if( aFieldNdx >= (int) m_FieldsBuf.size() )
aFieldNdx = m_FieldsBuf.size() - 1; aFieldNdx = m_FieldsBuf.size() - 1;
@ -552,9 +551,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers()
} }
/***********************************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::setRowItem( int aFieldNdx, const LIB_FIELD& aField ) void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::setRowItem( int aFieldNdx, const LIB_FIELD& aField )
/***********************************************************************************************/
{ {
wxASSERT( aFieldNdx >= 0 ); wxASSERT( aFieldNdx >= 0 );
@ -577,9 +574,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::setRowItem( int aFieldNdx, const LIB_FI
} }
/****************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel() void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel()
/****************************************************************/
{ {
unsigned fieldNdx = getSelectedFieldNdx(); unsigned fieldNdx = getSelectedFieldNdx();
@ -682,9 +677,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel()
} }
/*****************************************************************/
bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copyPanelToSelectedField() bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copyPanelToSelectedField()
/*****************************************************************/
{ {
unsigned fieldNdx = getSelectedFieldNdx(); unsigned fieldNdx = getSelectedFieldNdx();

View File

@ -338,7 +338,7 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
{ {
fn = wxFileName( m_library->GetFullFileName() ); fn = wxFileName( m_library->GetFullFileName() );
msg.Printf( _( "Modify library file <%s> ?" ), msg.Printf( _( "Modify library file <%s> ?" ),
GetChars( fn.GetFullPath() ) ); GetChars( fn.GetFullPath() ) );
if( !IsOK( this, msg ) ) if( !IsOK( this, msg ) )
@ -386,7 +386,7 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
catch( ... /* IO_ERROR ioe */ ) catch( ... /* IO_ERROR ioe */ )
{ {
libFileName.MakeAbsolute(); libFileName.MakeAbsolute();
msg.Printf( _( "Failed to create component library file <%s>" ), msg.Printf( _( "Failed to create component library file <%s>" ),
GetChars( libFileName.GetFullPath() ) ); GetChars( libFileName.GetFullPath() ) );
DisplayError( this, msg ); DisplayError( this, msg );
return false; return false;
@ -686,7 +686,7 @@ lost!\n\nClear the current component from the screen?" ) ) )
void LIB_EDIT_FRAME::SaveOnePartInMemory() void LIB_EDIT_FRAME::SaveOnePartInMemory()
{ {
LIB_COMPONENT* oldComponent; LIB_COMPONENT* oldComponent;
LIB_COMPONENT* Component; LIB_COMPONENT* component;
wxString msg; wxString msg;
if( m_component == NULL ) if( m_component == NULL )
@ -720,15 +720,15 @@ void LIB_EDIT_FRAME::SaveOnePartInMemory()
m_drawItem = m_lastDrawItem = NULL; m_drawItem = m_lastDrawItem = NULL;
if( oldComponent != NULL ) if( oldComponent != NULL )
Component = m_library->ReplaceComponent( oldComponent, m_component ); component = m_library->ReplaceComponent( oldComponent, m_component );
else else
Component = m_library->AddComponent( m_component ); component = m_library->AddComponent( m_component );
if( Component == NULL ) if( component == NULL )
return; return;
msg.Printf( _( "Component %s saved in library %s" ), msg.Printf( _( "Component %s saved in library %s" ),
GetChars( Component->GetName() ), GetChars( component->GetName() ),
GetChars( m_library->GetName() ) ); GetChars( m_library->GetName() ) );
SetStatusText( msg ); SetStatusText( msg );
} }

View File

@ -62,7 +62,7 @@ static LIB_COMPONENT* DummyCmp;
* convert a wxString to UTF8 and replace any control characters with a ~, * convert a wxString to UTF8 and replace any control characters with a ~,
* where a control character is one of the first ASCII values up to ' ' 32d. * where a control character is one of the first ASCII values up to ' ' 32d.
*/ */
std::string toUTFTildaText( const wxString& txt ) static std::string toUTFTildaText( const wxString& txt )
{ {
std::string ret = TO_UTF8( txt ); std::string ret = TO_UTF8( txt );
@ -957,8 +957,8 @@ bool SCH_COMPONENT::Save( FILE* f ) const
static wxString delimiters( wxT( " " ) ); static wxString delimiters( wxT( " " ) );
//this is redundant with the AR entries below, but it makes the // this is redundant with the AR entries below, but it makes the
//files backwards-compatible. // files backwards-compatible.
if( m_PathsAndReferences.GetCount() > 0 ) if( m_PathsAndReferences.GetCount() > 0 )
{ {
reference_fields = wxStringTokenize( m_PathsAndReferences[0], delimiters ); reference_fields = wxStringTokenize( m_PathsAndReferences[0], delimiters );
@ -1031,9 +1031,8 @@ bool SCH_COMPONENT::Save( FILE* f ) const
} }
// Fixed fields: // Fixed fields:
// Save fixed fields even they are non blank, // Save mandatory fields even if they are blank,
// because the visibility, size and orientation are set from libaries // because the visibility, size and orientation are set from libary editor.
// mainly for footprint names, for those who do not use CvPcb
for( unsigned i = 0; i<MANDATORY_FIELDS; ++i ) for( unsigned i = 0; i<MANDATORY_FIELDS; ++i )
{ {
SCH_FIELD* fld = GetField( i ); SCH_FIELD* fld = GetField( i );
@ -1085,10 +1084,8 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
{ {
newfmt = 1; newfmt = 1;
if( !aLine.ReadLine() ) if( !(line = aLine.ReadLine()) )
return true; return true;
line = aLine.Line();
} }
if( sscanf( &line[1], "%s %s", name1, name2 ) != 2 ) if( sscanf( &line[1], "%s %s", name1, name2 ) != 2 )
@ -1178,11 +1175,9 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
*/ */
for( ; ; ) for( ; ; )
{ {
if( !aLine.ReadLine() ) if( !(line = aLine.ReadLine()) )
return false; return false;
line = aLine.Line();
if( line[0] == 'U' ) if( line[0] == 'U' )
{ {
sscanf( line + 1, "%d %d %lX", &m_unit, &m_convert, &m_TimeStamp ); sscanf( line + 1, "%d %d %lX", &m_unit, &m_convert, &m_TimeStamp );
@ -1354,8 +1349,8 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
return false; return false;
} }
if( !aLine.ReadLine() || if( !(line = aLine.ReadLine()) ||
sscanf( ((char*)aLine), "%d %d %d %d", sscanf( line, "%d %d %d %d",
&m_transform.x1, &m_transform.x1,
&m_transform.y1, &m_transform.y1,
&m_transform.x2, &m_transform.x2,
@ -1368,11 +1363,9 @@ bool SCH_COMPONENT::Load( LINE_READER& aLine, wxString& aErrorMsg )
if( newfmt ) if( newfmt )
{ {
if( !aLine.ReadLine() ) if( !(line = aLine.ReadLine()) )
return false; return false;
line = aLine.Line();
if( strnicmp( "$End", line, 4 ) != 0 ) if( strnicmp( "$End", line, 4 ) != 0 )
{ {
aErrorMsg.Printf( wxT( "Component End expected at line %d, aborted" ), aErrorMsg.Printf( wxT( "Component End expected at line %d, aborted" ),