From 7a5386a1a15bc166a5d11120fffa44e3e82a338b Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 26 Feb 2013 12:25:30 +0100 Subject: [PATCH] Minor fixes and cleanup --- common/base_units.cpp | 41 ++++++++++++++++++----------- common/build_version.cpp | 4 +-- common/string.cpp | 17 ------------ eeschema/plot_schematic_SVG.cpp | 1 - eeschema/symbdraw.cpp | 9 ++++++- include/base_units.h | 8 ++++++ include/{dcsvg.h => dcsvg.h.unused} | 0 include/kicad_string.h | 8 ------ pcbnew/basepcbframe.cpp | 24 +++++------------ pcbnew/dialogs/dialog_SVG_print.cpp | 1 - pcbnew/set_grid.cpp | 33 ++++++++++++++++++----- 11 files changed, 77 insertions(+), 69 deletions(-) rename include/{dcsvg.h => dcsvg.h.unused} (100%) diff --git a/common/base_units.cpp b/common/base_units.cpp index a92baad094..7dcf548c95 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -124,6 +124,31 @@ wxString LengthDoubleToString( double aValue, bool aConvertToMils ) return text; } +/* Remove trailing 0 from a string containing a converted float number. + * the trailing 0 are removed if the mantissa has more + * than aTrailingZeroAllowed digits and some trailing 0 + */ +void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed ) +{ + struct lconv * lc = localeconv(); + char sep = lc->decimal_point[0]; + unsigned sep_pos = aStringValue.Find( sep ); + + if( sep_pos > 0 ) + { + // We want to keep at least aTrailingZeroAllowed digits after the separator + unsigned min_len = sep_pos + aTrailingZeroAllowed + 1; + + while( aStringValue.Len() > min_len ) + { + if( aStringValue.Last() == '0' ) + aStringValue.RemoveLast(); + else + break; + } + } +} + /* Convert a value to a string using double notation. * For readability, the mantissa has 3 or more digits (max 8 digits), @@ -153,21 +178,7 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymb // Strip trailing zeros. However, keep at least 3 digits in mantissa // For readability - struct lconv * lc = localeconv(); - char sep = lc->decimal_point[0]; - unsigned sep_pos = stringValue.Find( sep ); - - if( sep_pos > 0 ) - { - // We want to keep at least 3 digits after the separator - unsigned min_len = sep_pos + 4; - - while( stringValue.Len() > min_len ) - if( stringValue.Last() == '0' ) - stringValue.RemoveLast(); - else - break; - } + StripTrailingZeros( stringValue, 3 ); #endif if( aAddUnitSymbol ) diff --git a/common/build_version.cpp b/common/build_version.cpp index 9a1f5d3c46..50c1eb4080 100644 --- a/common/build_version.cpp +++ b/common/build_version.cpp @@ -7,9 +7,9 @@ #ifndef KICAD_BUILD_VERSION #if defined KICAD_GOST -# define KICAD_BUILD_VERSION "(2013-feb-21 GOST)" +# define KICAD_BUILD_VERSION "(2013-feb-26 GOST)" #else -# define KICAD_BUILD_VERSION "(2013-feb-21)" +# define KICAD_BUILD_VERSION "(2013-feb-26)" #endif #endif diff --git a/common/string.cpp b/common/string.cpp index 6d61c1d4ca..7bef64abb5 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -304,23 +304,6 @@ bool WildCompareString( const wxString& pattern, const wxString& string_to_tst, } -char* to_point( char* Text ) -{ - char* line = Text; - - if( Text == NULL ) - return NULL; - - for( ; *Text != 0; Text++ ) - { - if( *Text == ',' ) - *Text = '.'; - } - - return line; -} - - int RefDesStringCompare( const wxString& strFWord, const wxString& strSWord ) { // The different sections of the first string diff --git a/eeschema/plot_schematic_SVG.cpp b/eeschema/plot_schematic_SVG.cpp index 38bdc1421c..86d6bb4aba 100644 --- a/eeschema/plot_schematic_SVG.cpp +++ b/eeschema/plot_schematic_SVG.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include diff --git a/eeschema/symbdraw.cpp b/eeschema/symbdraw.cpp index 338be1d3ae..ddd33b4380 100644 --- a/eeschema/symbdraw.cpp +++ b/eeschema/symbdraw.cpp @@ -290,7 +290,14 @@ void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC ) SetCursor( wxCURSOR_HAND ); TempCopyComponent(); - m_drawItem->BeginEdit( IS_MOVED, GetScreen()->GetCrossHairPosition( true ) ); + + // For fields only, move the anchor point of the field + // to the cursor position to allow user to see the text justification + if( m_drawItem->Type() == LIB_FIELD_T ) + m_drawItem->BeginEdit( IS_MOVED, m_drawItem->GetPosition() ); + else + m_drawItem->BeginEdit( IS_MOVED, GetScreen()->GetCrossHairPosition( true ) ); + m_canvas->SetMouseCapture( RedrawWhileMovingCursor, AbortSymbolTraceOn ); m_canvas->CallMouseCapture( DC, wxDefaultPosition, true ); } diff --git a/include/base_units.h b/include/base_units.h index e73803554f..575011a0c2 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -37,6 +37,14 @@ #include #include +/** + * Function StripTrailingZeros + * Remove trailing 0 from a string containing a converted float number. + * The trailing 0 are removed if the mantissa has more + * than aTrailingZeroAllowed digits and some trailing 0 + */ +void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed = 1 ); + /** * Function To_User_Unit diff --git a/include/dcsvg.h b/include/dcsvg.h.unused similarity index 100% rename from include/dcsvg.h rename to include/dcsvg.h.unused diff --git a/include/kicad_string.h b/include/kicad_string.h index 379035c20c..91d5a0ad0c 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -98,14 +98,6 @@ bool WildCompareString( const wxString& pattern, const wxString& string_to_tst, bool case_sensitive = true ); -/** - * Function to_point - * converts a string used to compensate for internalization of printf(). It generates - * floating point numbers with a comma instead of point. - * @deprecated Use SetLocaleTo_C_standard instead. - */ -char* to_point( char* Text ); - /** * Function RefDesStringCompare * acts just like the strcmp function but treats numbers within the string text diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index af7fb9a9bd..c35d951f86 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -761,16 +761,13 @@ void PCB_BASE_FRAME::updateGridSelectBox() m_gridSelectBox->Clear(); wxString msg; - wxString format = _( "Grid"); + wxString format = _( "Grid:"); switch( g_UserUnit ) { - case INCHES: - format += wxT( " %.1f" ); - break; - + case INCHES: // the grid size is displayed in mils case MILLIMETRES: - format += wxT( " %.4f" ); + format += wxT( " %.6f" ); break; case UNSCALED_UNITS: @@ -782,20 +779,13 @@ void PCB_BASE_FRAME::updateGridSelectBox() { GRID_TYPE& grid = GetScreen()->GetGrid( i ); double value = To_User_Unit( g_UserUnit, grid.m_Size.x ); + if( g_UserUnit == INCHES ) + value *= 1000; if( grid.m_Id != ID_POPUP_GRID_USER ) { - switch( g_UserUnit ) - { - case INCHES: - msg.Printf( format.GetData(), value * 1000 ); - break; - - case MILLIMETRES: - case UNSCALED_UNITS: - msg.Printf( format.GetData(), value ); - break; - } + msg.Printf( format.GetData(), value ); + StripTrailingZeros( msg ); } else msg = _( "User Grid" ); diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index ae77c86018..664525884f 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/pcbnew/set_grid.cpp b/pcbnew/set_grid.cpp index 0ed158024a..0f42682c73 100644 --- a/pcbnew/set_grid.cpp +++ b/pcbnew/set_grid.cpp @@ -2,6 +2,28 @@ * @file set_grid.cpp * @brief Manage user grid. */ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.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 #include @@ -83,9 +105,9 @@ void DIALOG_SET_GRID::SetGridSize( const wxRealPoint& grid ) { wxString msg; - msg.Printf( wxT( "%.4f" ), grid.x ); + msg.Printf( wxT( "%.6f" ), grid.x ); m_OptGridSizeX->SetValue( msg ); - msg.Printf( wxT( "%.4f" ), grid.y ); + msg.Printf( wxT( "%.6f" ), grid.y ); m_OptGridSizeY->SetValue( msg ); } @@ -138,11 +160,8 @@ void DIALOG_SET_GRID::SetGridOrigin( const wxPoint& grid ) void DIALOG_SET_GRID::SetGridForFastSwitching( wxArrayString aGrids, int aGrid1, int aGrid2 ) { - for( wxArrayString::iterator i = aGrids.begin(); i != aGrids.end(); i++ ) - { - m_comboBoxGrid1->Append( *i ); - m_comboBoxGrid2->Append( *i ); - } + m_comboBoxGrid1->Append( aGrids ); + m_comboBoxGrid2->Append( aGrids ); m_comboBoxGrid1->SetSelection( aGrid1 ); m_comboBoxGrid2->SetSelection( aGrid2 );