From 680fe999b20ec783779b4f8f1dcca355f9840d09 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 25 Jun 2012 22:59:19 +0200 Subject: [PATCH] All: fix a truncation issue in ReturnValueFromString that creates sometimes a small error for values entered in dialogs. Pcbnew: fix a compatibility issue with nano version for zones parameters. --- common/base_units.cpp | 6 +-- pcbnew/class_board.h | 10 ---- pcbnew/class_zone.h | 1 - pcbnew/class_zone_settings.cpp | 12 +++-- pcbnew/dialogs/dialog_copper_zones.cpp | 66 ++++++++++++++++++------ pcbnew/dialogs/dialog_pad_properties.cpp | 1 + pcbnew/zones.h | 11 ++++ pcbnew/zones_by_polygon.cpp | 20 +++++-- pcbnew/zones_test_and_combine_areas.cpp | 24 --------- 9 files changed, 90 insertions(+), 61 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index acc8162e93..2b6bd7ecf6 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -188,7 +188,7 @@ double From_User_Unit( EDA_UNITS_T aUnit, double aValue ) int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue ) { - int Value; + double value; double dtmp = 0; // Acquire the 'right' decimal point separator @@ -239,9 +239,9 @@ int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue ) dtmp /= 1000; } - Value = From_User_Unit( aUnits, dtmp ); + value = From_User_Unit( aUnits, dtmp ); - return Value; + return KiROUND( value ); } diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index d1bd06e832..59cbdc76eb 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -1048,16 +1048,6 @@ public: */ ZONE_CONTAINER* InsertArea( int netcode, int iarea, int layer, int x, int y, int hatch ); - /** - * Function CompleteArea - * complete copper area contour by adding a line from last to first corner - * if there is only 1 or 2 corners, remove (delete) the area - * @param area_to_complete = area to complete or remove - * @param style = style of last corner - * @return 1 if Ok, 0 if area removed - */ - int CompleteArea( ZONE_CONTAINER* area_to_complete, int style ); - /** * Function TestAreaPolygon * Test an area for self-intersection. diff --git a/pcbnew/class_zone.h b/pcbnew/class_zone.h index b4d3f6aefa..2a2c9099a8 100644 --- a/pcbnew/class_zone.h +++ b/pcbnew/class_zone.h @@ -48,7 +48,6 @@ class PCB_EDIT_FRAME; class BOARD; class ZONE_CONTAINER; - /** * Struct SEGMENT * is a simple container used when filling areas with segments diff --git a/pcbnew/class_zone_settings.cpp b/pcbnew/class_zone_settings.cpp index 09f98f60c9..174033d77f 100644 --- a/pcbnew/class_zone_settings.cpp +++ b/pcbnew/class_zone_settings.cpp @@ -39,8 +39,10 @@ ZONE_SETTINGS::ZONE_SETTINGS() { m_ZonePriority = 0; m_FillMode = 0; // Mode for filling zone : 1 use segments, 0 use polygons - m_ZoneClearance = 200; // Clearance value - m_ZoneMinThickness = 100; // Min thickness value in filled areas + // Clearance value + m_ZoneClearance = Mils2iu( ZONE_CLEARANCE_MIL ); + // Min thickness value in filled areas (this is the minimum width of copper to fill solid areas) : + m_ZoneMinThickness = Mils2iu( ZONE_THICKNESS_MIL ); m_NetcodeSelection = 0; // Net code selection for the current zone m_CurrentZone_Layer = 0; // Layer used to create the current zone m_Zone_HatchingStyle = CPolyLine::DIAGONAL_EDGE; // Option to show the zone area (outlines only, short hatches or full hatches @@ -49,8 +51,10 @@ ZONE_SETTINGS::ZONE_SETTINGS() // ARC_APPROX_SEGMENTS_COUNT_LOW_DEF // or ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF segments - m_ThermalReliefGap = 200; // tickness of the gap in thermal reliefs - m_ThermalReliefCopperBridge = 200; // tickness of the copper bridge in thermal reliefs + // tickness of the gap in thermal reliefs: + m_ThermalReliefGap = Mils2iu( ZONE_THERMAL_RELIEF_GAP_MIL ); + // tickness of the copper bridge in thermal reliefs: + m_ThermalReliefCopperBridge = Mils2iu( ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL ); m_PadConnection = THERMAL_PAD; // How pads are covered by copper in zone diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index 970da8c103..e3e08bf146 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -1,19 +1,39 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: dialog_copper_zones.cpp -// Author: jean-pierre Charras -// Created: 09/oct/2008 -// Licence: GNU License -///////////////////////////////////////////////////////////////////////////// +/** + * @file dialog_copper_zones.cpp + */ + +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr + * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 1992-2012 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 #include #include #include #include #include #include -#include #include #include @@ -370,20 +390,25 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab // Test if this is a reasonable value for this parameter // A too large value can hang Pcbnew - #define CLEARANCE_MAX_VALUE 100*IU_PER_MILS + #define CLEARANCE_MAX_VALUE ZONE_CLEARANCE_MAX_VALUE_MIL*IU_PER_MILS if( m_settings.m_ZoneClearance > CLEARANCE_MAX_VALUE ) { - DisplayError( this, _( "Clearance must be smaller than 0.5\" / 12.7 mm." ) ); + wxString msg; + msg.Printf( _( "Clearance must be smaller than %f\" / %f mm." ), + ZONE_CLEARANCE_MAX_VALUE_MIL / 1000.0, ZONE_CLEARANCE_MAX_VALUE_MIL * 0.0254 ); + DisplayError( this, msg ); return false; } txtvalue = m_ZoneMinThicknessCtrl->GetValue(); m_settings.m_ZoneMinThickness = ReturnValueFromString( g_UserUnit, txtvalue ); - if( m_settings.m_ZoneMinThickness < (1*IU_PER_MILS) ) + if( m_settings.m_ZoneMinThickness < (ZONE_THICKNESS_MIN_VALUE_MIL*IU_PER_MILS) ) { - DisplayError( this, - _( "Minimum width must be larger than 0.001\" / 0.0254 mm." ) ); + wxString msg; + msg.Printf( _( "Minimum width must be larger than %f\" / %f mm." ), + ZONE_THICKNESS_MIN_VALUE_MIL / 1000.0, ZONE_THICKNESS_MIN_VALUE_MIL * 0.0254 ); + DisplayError( this, msg ); return false; } @@ -402,9 +427,20 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab m_settings.m_ThermalReliefCopperBridge = ReturnValueFromTextCtrl( *m_CopperWidthValue ); - m_Config->Write( ZONE_THERMAL_RELIEF_GAP_STRING_KEY, (long) m_settings.m_ThermalReliefGap ); + if( m_Config ) + { + m_Config->Write( ZONE_CLEARANCE_WIDTH_STRING_KEY, + (double) m_settings.m_ZoneClearance / IU_PER_MILS ); - m_Config->Write( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY, (long) m_settings.m_ThermalReliefCopperBridge ); + m_Config->Write( ZONE_MIN_THICKNESS_WIDTH_STRING_KEY, + (double) m_settings.m_ZoneMinThickness / IU_PER_MILS ); + + m_Config->Write( ZONE_THERMAL_RELIEF_GAP_STRING_KEY, + (double) m_settings.m_ThermalReliefGap / IU_PER_MILS ); + + m_Config->Write( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY, + (double) m_settings.m_ThermalReliefCopperBridge / IU_PER_MILS ); + } if( m_settings.m_ThermalReliefCopperBridge <= m_settings.m_ZoneMinThickness ) { diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 1dce2137be..0dc3dd5058 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -479,6 +479,7 @@ void DIALOG_PAD_PROPERTIES::initValues() wxCommandEvent cmd_event; setPadLayersList( m_dummyPad->GetLayerMask() ); OnDrillShapeSelected( cmd_event ); + OnPadShapeSelection( cmd_event ); } diff --git a/pcbnew/zones.h b/pcbnew/zones.h index 65d7dc7dba..69a2b61720 100644 --- a/pcbnew/zones.h +++ b/pcbnew/zones.h @@ -11,6 +11,17 @@ #define ZONE_NET_FILTER_STRING_KEY wxT( "Zone_Filter_Opt" ) #define ZONE_THERMAL_RELIEF_GAP_STRING_KEY wxT( "Zone_TH_Gap" ) #define ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY wxT( "Zone_TH_Copper_Width" ) +#define ZONE_CLEARANCE_WIDTH_STRING_KEY wxT( "Zone_Clearance" ) +#define ZONE_MIN_THICKNESS_WIDTH_STRING_KEY wxT( "Zone_Thickness" ) + +// Default values in mils for parameters in ZONE_CONTAINER +#define ZONE_THERMAL_RELIEF_GAP_MIL 20 // default value for ZONE_SETTINGS::m_ThermalReliefGap +#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL 20 // default value for ZONE_SETTINGS::m_ThermalReliefCopperBridge +#define ZONE_THICKNESS_MIL 10 // default value for ZONE_SETTINGS::m_ZoneMinThickness +#define ZONE_THICKNESS_MIN_VALUE_MIL 1 // minimum acceptable value for ZONE_SETTINGS::m_ZoneMinThickness +#define ZONE_CLEARANCE_MIL 20 // default value for ZONE_SETTINGS::m_ZoneClearance +#define ZONE_CLEARANCE_MAX_VALUE_MIL 500 // maximum acceptable value for ZONE_SETTINGS::m_ZoneClearance + /// Exit codes for zone editing dialogs enum ZONE_EDIT_T { diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index daf585f210..0d5dcf999f 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -536,12 +536,24 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) zone->SetNet( zoneInfo.m_NetcodeSelection ); zone->SetNetNameFromNetCode( ); } + double tmp = ZONE_THERMAL_RELIEF_GAP_MIL; + wxGetApp().GetSettings()->Read( ZONE_THERMAL_RELIEF_GAP_STRING_KEY, &tmp ); + zoneInfo.m_ThermalReliefGap = KiROUND( tmp * IU_PER_MILS); - wxGetApp().GetSettings()->Read( ZONE_THERMAL_RELIEF_GAP_STRING_KEY, - &zoneInfo.m_ThermalReliefGap ); - + tmp = ZONE_THERMAL_RELIEF_COPPER_WIDTH_MIL; wxGetApp().GetSettings()->Read( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY, - &zoneInfo.m_ThermalReliefCopperBridge ); + &tmp ); + zoneInfo.m_ThermalReliefCopperBridge = KiROUND( tmp * IU_PER_MILS ); + + tmp = ZONE_CLEARANCE_MIL; + wxGetApp().GetSettings()->Read( ZONE_CLEARANCE_WIDTH_STRING_KEY, + &tmp ); + zoneInfo.m_ZoneClearance = KiROUND( tmp * IU_PER_MILS ); + + tmp = ZONE_THICKNESS_MIL; + wxGetApp().GetSettings()->Read( ZONE_MIN_THICKNESS_WIDTH_STRING_KEY, + &tmp ); + zoneInfo.m_ZoneMinThickness = KiROUND( tmp * IU_PER_MILS ); zoneInfo.m_CurrentZone_Layer = zone->GetLayer(); diff --git a/pcbnew/zones_test_and_combine_areas.cpp b/pcbnew/zones_test_and_combine_areas.cpp index b22ea9c4a2..c06e96feac 100644 --- a/pcbnew/zones_test_and_combine_areas.cpp +++ b/pcbnew/zones_test_and_combine_areas.cpp @@ -124,30 +124,6 @@ ZONE_CONTAINER* BOARD::InsertArea( int netcode, int iarea, int layer, int x, int } -/** - * Function CompleteArea - * complete copper area contour by adding a line from last to first corner - * if there is only 1 or 2 corners, remove (delete) the area - * @param area_to_complete = area to complete or remove - * @param style = style of last corner - * @return 1 if Ok, 0 if area removed - */ -int BOARD::CompleteArea( ZONE_CONTAINER* area_to_complete, int style ) -{ - if( area_to_complete->m_Poly->GetNumCorners() > 2 ) - { - area_to_complete->m_Poly->Close( style ); - return 1; - } - else - { - Delete( area_to_complete ); - } - - return 0; -} - - /** * Function TestAreaPolygon * Test an area for self-intersection.