Commit c4c58e12 authored by Dick Hollenbeck's avatar Dick Hollenbeck

copyright and formatting

parent 8bafc54c
...@@ -623,7 +623,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -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
......
/*******************************************************************************/
/* 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; ...@@ -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: ...@@ -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 ) ...@@ -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( ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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& ...@@ -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 ...@@ -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 ...@@ -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() ...@@ -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 ...@@ -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() ...@@ -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();
......
...@@ -686,7 +686,7 @@ lost!\n\nClear the current component from the screen?" ) ) ) ...@@ -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() ...@@ -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 );
} }
...@@ -62,7 +62,7 @@ static LIB_COMPONENT* DummyCmp; ...@@ -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 ...@@ -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 ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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" ),
......
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