Commit cbee2477 authored by Marco Mattila's avatar Marco Mattila
Browse files

Add zone corner smoothing to pcbnew.

parent 75f332ae
Loading
Loading
Loading
Loading
+28 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@


#include "protos.h"
#include "protos.h"
#include "richio.h"
#include "richio.h"
#include "class_zone_setting.h"


/************************/
/************************/
/* class ZONE_CONTAINER */
/* class ZONE_CONTAINER */
@@ -30,6 +31,9 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* parent ) :
    m_CornerSelection = -1;
    m_CornerSelection = -1;
    m_IsFilled = false;                         // fill status : true when the zone is filled
    m_IsFilled = false;                         // fill status : true when the zone is filled
    m_FillMode = 0;                             // How to fill areas: 0 = use filled polygons, != 0 fill with segments
    m_FillMode = 0;                             // How to fill areas: 0 = use filled polygons, != 0 fill with segments
    smoothedPoly = NULL;
    cornerSmoothingType = ZONE_SETTING::SMOOTHING_NONE;
    cornerRadius = 0;
    utility    = 0;                             // flags used in polygon calculations
    utility    = 0;                             // flags used in polygon calculations
    utility2   = 0;                             // flags used in polygon calculations
    utility2   = 0;                             // flags used in polygon calculations
    m_Poly     = new CPolyLine();               // Outlines
    m_Poly     = new CPolyLine();               // Outlines
@@ -170,6 +174,11 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const
    if( ret < 3 )
    if( ret < 3 )
        return false;
        return false;


    ret = fprintf( aFile,
                   "ZSmoothing %d %d\n",
                   cornerSmoothingType, cornerRadius );
    if( ret < 2 )
        return false;


    // Save the corner list
    // Save the corner list
    for( item_pos = 0; item_pos < corners_count; item_pos++ )
    for( item_pos = 0; item_pos < corners_count; item_pos++ )
@@ -320,6 +329,25 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader )
            }
            }
            /* Set hatch mode later, after reading outlines corners data */
            /* Set hatch mode later, after reading outlines corners data */
        }
        }
        else if( strnicmp( Line, "ZSmoothing", 10 ) == 0 )
        {
            int tempSmoothingType;
            int tempCornerRadius;
            text = Line + 10;
            ret  = sscanf( text, "%d %d", &tempSmoothingType, &tempCornerRadius );

            if( ret < 2 )
                return false;

            if( tempSmoothingType >= ZONE_SETTING::SMOOTHING_LAST)
                return false;

            if( tempSmoothingType < 0 )
                return false;

            cornerSmoothingType = tempSmoothingType;
            SetCornerRadius( tempCornerRadius );
        }
        else if( strnicmp( Line, "ZOptions", 8 ) == 0 )    // Options info found
        else if( strnicmp( Line, "ZOptions", 8 ) == 0 )    // Options info found
        {
        {
            int  fillmode = 1;
            int  fillmode = 1;
+35 −1
Original line number Original line Diff line number Diff line
@@ -9,6 +9,7 @@
#include "gr_basic.h"
#include "gr_basic.h"
#include "PolyLine.h"
#include "PolyLine.h"
#include "richio.h"
#include "richio.h"
#include "class_zone_setting.h"


/* a small class used when filling areas with segments */
/* a small class used when filling areas with segments */
class SEGMENT
class SEGMENT
@@ -61,7 +62,10 @@ public:
                                                *  ( m_FillMode == 1 )
                                                *  ( m_FillMode == 1 )
                                                *  in this case segments have m_ZoneMinThickness width
                                                *  in this case segments have m_ZoneMinThickness width
                                                */
                                                */

private:
    CPolyLine*            smoothedPoly;         // Corner-smoothed version of m_Poly
    int                   cornerSmoothingType;
    unsigned int          cornerRadius;
public:
public:
    ZONE_CONTAINER( BOARD* parent );
    ZONE_CONTAINER( BOARD* parent );
    ~ZONE_CONTAINER();
    ~ZONE_CONTAINER();
@@ -366,6 +370,7 @@ public:
    {
    {
        return m_Poly->GetHatchStyle();
        return m_Poly->GetHatchStyle();
    }
    }

    /**
    /**
     * Function IsSame
     * Function IsSame
     * test is 2 zones are equivalent:
     * test is 2 zones are equivalent:
@@ -374,6 +379,35 @@ public:
     * @param aZoneToCompare = zone to compare with "this"
     * @param aZoneToCompare = zone to compare with "this"
     */
     */
    bool IsSame( const ZONE_CONTAINER &aZoneToCompare);
    bool IsSame( const ZONE_CONTAINER &aZoneToCompare);

    /**
     * Function GetSmoothedPoly
     * returns a pointer to the corner-smoothed version of
     * m_Poly if it exists, otherwise it returns m_Poly.
     * @return CPolyLine* - pointer to the polygon.
     */
    CPolyLine* GetSmoothedPoly() const
    {
        if( smoothedPoly )
            return smoothedPoly;
        else
            return m_Poly;
    };

    void SetCornerSmoothingType( int aType ) { cornerSmoothingType = aType; };
    int  GetCornerSmoothingType() const { return cornerSmoothingType; };

    void SetCornerRadius( unsigned int aRadius )
    {
        if( aRadius > MAX_ZONE_CORNER_RADIUS )
            cornerRadius = MAX_ZONE_CORNER_RADIUS;
        else if( aRadius < 0 )
            cornerRadius = 0;
        else
            cornerRadius = aRadius;
    };

    unsigned int GetCornerRadius() const { return cornerRadius; };
};
};




+7 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,9 @@ ZONE_SETTING::ZONE_SETTING( void )
    m_ThermalReliefCopperBridgeValue = 200;                         // tickness of the copper bridge in thermal reliefs
    m_ThermalReliefCopperBridgeValue = 200;                         // tickness of the copper bridge in thermal reliefs


    m_Zone_Pad_Options = THERMAL_PAD;                               // How pads are covered by copper in zone
    m_Zone_Pad_Options = THERMAL_PAD;                               // How pads are covered by copper in zone

    cornerSmoothingType = SMOOTHING_NONE;
    cornerRadius = 0;
}
}




@@ -57,6 +60,8 @@ void ZONE_SETTING::ImportSetting( const ZONE_CONTAINER& aSource )
    m_ThermalReliefGapValue = aSource.m_ThermalReliefGapValue;
    m_ThermalReliefGapValue = aSource.m_ThermalReliefGapValue;
    m_ThermalReliefCopperBridgeValue = aSource.m_ThermalReliefCopperBridgeValue;
    m_ThermalReliefCopperBridgeValue = aSource.m_ThermalReliefCopperBridgeValue;
    m_Zone_Pad_Options = aSource.m_PadOption;
    m_Zone_Pad_Options = aSource.m_PadOption;
    cornerSmoothingType = aSource.GetCornerSmoothingType();
    cornerRadius = aSource.GetCornerRadius();
}
}




@@ -79,6 +84,8 @@ void ZONE_SETTING::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport )
    aTarget.m_ThermalReliefGapValue = m_ThermalReliefGapValue;
    aTarget.m_ThermalReliefGapValue = m_ThermalReliefGapValue;
    aTarget.m_ThermalReliefCopperBridgeValue = m_ThermalReliefCopperBridgeValue;
    aTarget.m_ThermalReliefCopperBridgeValue = m_ThermalReliefCopperBridgeValue;
    aTarget.m_PadOption = m_Zone_Pad_Options;
    aTarget.m_PadOption = m_Zone_Pad_Options;
    aTarget.SetCornerSmoothingType( cornerSmoothingType );
    aTarget.SetCornerRadius( cornerRadius );
    if( aFullExport )
    if( aFullExport )
    {
    {
        aTarget.SetNet( m_NetcodeSelection );
        aTarget.SetNet( m_NetcodeSelection );
+23 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,7 @@
#ifndef ZONE_SETTING_H
#ifndef ZONE_SETTING_H
#define ZONE_SETTING_H
#define ZONE_SETTING_H


#define MAX_ZONE_CORNER_RADIUS 4000


/*************************************************/
/*************************************************/
/* Class ZONE_SETTING to handle zones parameters */
/* Class ZONE_SETTING to handle zones parameters */
@@ -12,6 +13,12 @@
class ZONE_SETTING
class ZONE_SETTING
{
{
public:
public:
    enum {
        SMOOTHING_NONE,
        SMOOTHING_CHAMFER,
        SMOOTHING_FILLET,
        SMOOTHING_LAST
    };
    int  m_FillMode;                                    // Mode for filling zone : 1 use segments, 0 use polygons
    int  m_FillMode;                                    // Mode for filling zone : 1 use segments, 0 use polygons
    int  m_ZoneClearance;                               // Clearance value
    int  m_ZoneClearance;                               // Clearance value
    int  m_ZoneMinThickness;                            // Min thickness value in filled areas
    int  m_ZoneMinThickness;                            // Min thickness value in filled areas
@@ -23,6 +30,9 @@ public:
    long m_ThermalReliefGapValue;                       // tickness of the gap in thermal reliefs
    long m_ThermalReliefGapValue;                       // tickness of the gap in thermal reliefs
    long m_ThermalReliefCopperBridgeValue;              // tickness of the copper bridge in thermal reliefs
    long m_ThermalReliefCopperBridgeValue;              // tickness of the copper bridge in thermal reliefs
    int  m_Zone_Pad_Options;                            // How pads are covered by copper in zone
    int  m_Zone_Pad_Options;                            // How pads are covered by copper in zone
private:
    int  cornerSmoothingType;                           // Corner smoothing type
    unsigned int  cornerRadius;                         // Corner chamfer distance / fillet radius
public:
public:
    ZONE_SETTING( void );
    ZONE_SETTING( void );


@@ -43,6 +53,19 @@ public:
     *      m_NetcodeSelection
     *      m_NetcodeSelection
     */
     */
    void ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport = true);
    void ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport = true);

    void SetCornerSmoothingType( int aType) { cornerSmoothingType = aType; };
    int  GetCornerSmoothingType() const { return cornerSmoothingType; };
    void SetCornerRadius( int aRadius )
    {
        if( aRadius > MAX_ZONE_CORNER_RADIUS )
            cornerRadius = MAX_ZONE_CORNER_RADIUS;
        else if( aRadius < 0 )
            cornerRadius = 0;
        else
            cornerRadius = aRadius;
    };
    unsigned int  GetCornerRadius() const { return cornerRadius; };
};
};




+45 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include "zones.h"
#include "zones.h"


#include "dialog_copper_zones.h"
#include "dialog_copper_zones.h"
#include "class_zone_setting.h"


#define LAYER_BITMAP_SIZE_X 20
#define LAYER_BITMAP_SIZE_X 20
#define LAYER_BITMAP_SIZE_Y 10
#define LAYER_BITMAP_SIZE_Y 10
@@ -124,6 +125,13 @@ void dialog_copper_zone::initDialog()
                          m_Zone_Setting->m_ThermalReliefCopperBridgeValue,
                          m_Zone_Setting->m_ThermalReliefCopperBridgeValue,
                          PCB_INTERNAL_UNIT );
                          PCB_INTERNAL_UNIT );


    m_cornerSmoothingChoice->SetSelection( m_Zone_Setting->GetCornerSmoothingType() );

    AddUnitSymbol( *m_cornerSmoothingTitle, g_UserUnit );
    PutValueInLocalUnits( *m_cornerSmoothingCtrl,
                          m_Zone_Setting->GetCornerRadius(),
                          PCB_INTERNAL_UNIT );

    switch( m_Zone_Setting->m_Zone_HatchingStyle )
    switch( m_Zone_Setting->m_Zone_HatchingStyle )
    {
    {
    case CPolyLine::NO_HATCH:
    case CPolyLine::NO_HATCH:
@@ -186,6 +194,9 @@ void dialog_copper_zone::initDialog()
    // Build list of nets:
    // Build list of nets:
    m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
    m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter );
    buildAvailableListOfNets();
    buildAvailableListOfNets();

    wxCommandEvent event;
    OnCornerSmoothingModeChoice( event );
}
}




@@ -203,6 +214,35 @@ void dialog_copper_zone::OnClose( wxCloseEvent& event )
}
}




void dialog_copper_zone::OnCornerSmoothingModeChoice( wxCommandEvent& event )
{
    int selection = m_cornerSmoothingChoice->GetSelection();

    switch( selection )
    {
    case ZONE_SETTING::SMOOTHING_NONE:
        m_cornerSmoothingTitle->Enable( false );
        m_cornerSmoothingCtrl->Enable( false );
        break;
    case ZONE_SETTING::SMOOTHING_CHAMFER:
        m_cornerSmoothingTitle->Enable( true );
        m_cornerSmoothingCtrl->Enable( true );
        m_cornerSmoothingTitle->SetLabel( wxT( "Chamfer distance" ) );
        AddUnitSymbol( *m_cornerSmoothingTitle, g_UserUnit );
        break;
    case ZONE_SETTING::SMOOTHING_FILLET:
        m_cornerSmoothingTitle->Enable( true );
        m_cornerSmoothingCtrl->Enable( true );
        m_cornerSmoothingTitle->SetLabel( wxT( "Fillet radius" ) );
        AddUnitSymbol( *m_cornerSmoothingTitle, g_UserUnit );
        break;
    }

    Layout();
    m_MainBoxSizer->SetSizeHints( this );
}


/********************************************************************************************/
/********************************************************************************************/
bool dialog_copper_zone::AcceptOptions( bool aPromptForErrors, bool aUseExportableSetupOnly )
bool dialog_copper_zone::AcceptOptions( bool aPromptForErrors, bool aUseExportableSetupOnly )
/********************************************************************************************/
/********************************************************************************************/
@@ -282,6 +322,10 @@ bool dialog_copper_zone::AcceptOptions( bool aPromptForErrors, bool aUseExportab
        return false;
        return false;
    }
    }


    m_Zone_Setting->SetCornerSmoothingType( m_cornerSmoothingChoice->GetSelection() );
    txtvalue = m_cornerSmoothingCtrl->GetValue();
    m_Zone_Setting->SetCornerRadius( ReturnValueFromString( g_UserUnit, txtvalue, m_Parent->m_InternalUnits ) );

    if( m_OrientEdgesOpt->GetSelection() == 0 )
    if( m_OrientEdgesOpt->GetSelection() == 0 )
        g_Zone_45_Only = FALSE;
        g_Zone_45_Only = FALSE;
    else
    else
@@ -493,6 +537,7 @@ void dialog_copper_zone::buildAvailableListOfNets()
    m_ListNetNameSelection->Clear();
    m_ListNetNameSelection->Clear();
    listNetName.Insert( wxT( "<no net>" ), 0 );
    listNetName.Insert( wxT( "<no net>" ), 0 );
    m_ListNetNameSelection->InsertItems( listNetName, 0 );
    m_ListNetNameSelection->InsertItems( listNetName, 0 );
    m_ListNetNameSelection->SetSelection( 0 );


    // Ensure current select net for the zone is visible:
    // Ensure current select net for the zone is visible:
    int net_select = m_Zone_Setting->m_NetcodeSelection;
    int net_select = m_Zone_Setting->m_NetcodeSelection;
Loading