diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 05dec19878..c5b0e57ab6 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -623,7 +623,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter ) LIB_FIELDS fields; GetFields( fields ); - // Fixed fields: + // Mandatory fields: // 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 diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index c4ddee491e..d4f5b2159e 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -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 + * 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 @@ -29,31 +51,29 @@ static int s_SelectedRow; #define COLUMN_FIELD_NAME 0 #define COLUMN_TEXT 1 -/*****************************************************************************************/ 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 m_FieldsBuf; - public: 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: - // Events handlers: void OnInitDialog( wxInitDialogEvent& event ); void OnListItemDeselected( wxListEvent& event ); void OnListItemSelected( wxListEvent& 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 moveUpButtonHandler( wxCommandEvent& event ); void OnCancelButtonClick( wxCommandEvent& event ); void OnOKButtonClick( wxCommandEvent& event ); @@ -102,6 +122,13 @@ private: for( unsigned ii = MANDATORY_FIELDS; ii 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( LIB_EDIT_FRAME* aParent, LIB_COMPONENT* aLibEntry ) : DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE( aParent ) -/***********************************************************************/ { m_parent = aParent; 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 ) -/**********************************************************************************/ { m_skipCopyFromPanel = false; 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 ) -/**********************************************************************************/ { 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 ) -/**********************************************************************************/ { // remember the selected row, statically 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 ) -/***********************************************************************************/ { EndModal( 1 ); } -/**********************************************************************************/ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event ) -/**********************************************************************************/ { if( !copyPanelToSelectedField() ) return; // 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" ) ); 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() ) { - wxString msg; - msg.Printf( _( "A new name is entered for this component\n\ -An alias %s already exists!\nCannot update this component" ), - GetChars( newvalue ) ); + wxString msg = wxString::Format( + _( "A new name is entered for this component\n" + "An alias %s already exists!\n" + "Cannot update this component" ), + GetChars( newvalue ) + ); DisplayError( this, msg ); return; } /* End unused code */ - /* save old cmp in undo list */ + // save old cmp in undo list m_parent->SaveCopyInUndoList( m_libEntry, IS_CHANGED ); // 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 ) -/*****************************************************************************************/ -/* 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(); @@ -342,9 +345,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEven } -/*************************************************************************************/ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB:: moveUpButtonHandler( wxCommandEvent& event ) -/*************************************************************************************/ { 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 ) -/****************************************************************************/ { - /* deselect old selection, but I think this is done by single selection flag within fieldListCtrl - * fieldListCtrl->SetItemState( s_SelectedRow, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); - */ + // deselect old selection, but I think this is done by single selection + // flag within fieldListCtrl + // fieldListCtrl->SetItemState( s_SelectedRow, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); if( aFieldNdx >= (int) m_FieldsBuf.size() ) 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 ) -/***********************************************************************************************/ { 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() -/****************************************************************/ { unsigned fieldNdx = getSelectedFieldNdx(); @@ -682,9 +677,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel() } -/*****************************************************************/ bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copyPanelToSelectedField() -/*****************************************************************/ { unsigned fieldNdx = getSelectedFieldNdx(); diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 036e07d260..bb615e3069 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -338,7 +338,7 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile ) { fn = wxFileName( m_library->GetFullFileName() ); - msg.Printf( _( "Modify library file <%s> ?" ), + msg.Printf( _( "Modify library file <%s> ?" ), GetChars( fn.GetFullPath() ) ); if( !IsOK( this, msg ) ) @@ -386,7 +386,7 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile ) catch( ... /* IO_ERROR ioe */ ) { libFileName.MakeAbsolute(); - msg.Printf( _( "Failed to create component library file <%s>" ), + msg.Printf( _( "Failed to create component library file <%s>" ), GetChars( libFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; @@ -686,7 +686,7 @@ lost!\n\nClear the current component from the screen?" ) ) ) void LIB_EDIT_FRAME::SaveOnePartInMemory() { LIB_COMPONENT* oldComponent; - LIB_COMPONENT* Component; + LIB_COMPONENT* component; wxString msg; if( m_component == NULL ) @@ -720,15 +720,15 @@ void LIB_EDIT_FRAME::SaveOnePartInMemory() m_drawItem = m_lastDrawItem = NULL; if( oldComponent != NULL ) - Component = m_library->ReplaceComponent( oldComponent, m_component ); + component = m_library->ReplaceComponent( oldComponent, m_component ); else - Component = m_library->AddComponent( m_component ); + component = m_library->AddComponent( m_component ); - if( Component == NULL ) + if( component == NULL ) return; msg.Printf( _( "Component %s saved in library %s" ), - GetChars( Component->GetName() ), + GetChars( component->GetName() ), GetChars( m_library->GetName() ) ); SetStatusText( msg ); } diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index bf9f3bc7f8..00ab0bb907 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -62,7 +62,7 @@ static LIB_COMPONENT* DummyCmp; * 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. */ -std::string toUTFTildaText( const wxString& txt ) +static std::string toUTFTildaText( const wxString& txt ) { std::string ret = TO_UTF8( txt ); @@ -957,8 +957,8 @@ bool SCH_COMPONENT::Save( FILE* f ) const static wxString delimiters( wxT( " " ) ); - //this is redundant with the AR entries below, but it makes the - //files backwards-compatible. + // this is redundant with the AR entries below, but it makes the + // files backwards-compatible. if( m_PathsAndReferences.GetCount() > 0 ) { reference_fields = wxStringTokenize( m_PathsAndReferences[0], delimiters ); @@ -1031,9 +1031,8 @@ bool SCH_COMPONENT::Save( FILE* f ) const } // Fixed fields: - // Save fixed fields even they are non blank, - // because the visibility, size and orientation are set from libaries - // mainly for footprint names, for those who do not use CvPcb + // Save mandatory fields even if they are blank, + // because the visibility, size and orientation are set from libary editor. for( unsigned i = 0; i