class_board_design_settings.cpp 9.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * 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
 */

24 25 26 27 28
/**
 * @file class_board_design_settings.cpp
 * BOARD_DESIGN_SETTINGS class functions.
 */

29 30 31
#include <fctsys.h>
#include <common.h>
#include <layers_id_colors_and_visibility.h>
charras's avatar
charras committed
32

33 34
#include <pcbnew.h>
#include <class_board_design_settings.h>
charras's avatar
charras committed
35

36
#include <class_track.h>
37
#include <convert_from_iu.h>
charras's avatar
charras committed
38

39 40 41 42 43 44 45 46 47 48 49
// Board thickness, mainly for 3D view:
#define DEFAULT_BOARD_THICKNESS_MM   1.6

// Default values for some board items
#define DEFAULT_TEXT_PCB_SIZE  Millimeter2iu( 1.5 )
#define DEFAULT_TEXT_PCB_THICKNESS  Millimeter2iu( 0.3 )
#define DEFAULT_PCB_EDGE_THICKNESS  Millimeter2iu( 0.15 )
#define DEFAULT_GRAPHIC_THICKNESS   Millimeter2iu( 0.2 )
#define DEFAULT_TEXT_MODULE_SIZE    Millimeter2iu( 1.5 )
#define DEFAULT_GR_MODULE_THICKNESS Millimeter2iu( 0.15 )

50
#define DEFAULT_SOLDERMASK_CLEARANCE Millimeter2iu( 0.2 )
51
#define DEFAULT_SOLDERMASK_MIN_WIDTH Millimeter2iu( 0.0 )
52

charras's avatar
charras committed
53

Dick Hollenbeck's avatar
Dick Hollenbeck committed
54
BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() :
55
    m_Pad_Master( NULL )
charras's avatar
charras committed
56
{
57 58
    m_EnabledLayers = ALL_LAYERS;               // All layers enabled at first.
                                                // SetCopperLayerCount() will adjust this.
Dick Hollenbeck's avatar
Dick Hollenbeck committed
59 60 61 62

    SetVisibleLayers( FULL_LAYERS );

    // set all but hidden text as visible.
Dick Hollenbeck's avatar
Dick Hollenbeck committed
63
    m_VisibleElements = ~( 1 << MOD_TEXT_INVISIBLE );
64 65 66 67 68 69 70 71 72

    SetCopperLayerCount( 2 );                   // Default design is a double sided board

    // via type (VIA_BLIND_BURIED, VIA_THROUGH VIA_MICROVIA).
    m_CurrentViaType = VIA_THROUGH;

    // if true, when creating a new track starting on an existing track, use this track width
    m_UseConnectedTrackWidth = false;

73
    m_BlindBuriedViaAllowed = false;            // true to allow blind/buried vias
74
    m_MicroViasAllowed = false;                 // true to allow micro vias
75

76
    m_DrawSegmentWidth = DEFAULT_GRAPHIC_THICKNESS;     // current graphic line width (not EDGE layer)
77

78 79
    m_EdgeSegmentWidth = DEFAULT_PCB_EDGE_THICKNESS;    // current graphic line width (EDGE layer only)
    m_PcbTextWidth     = DEFAULT_TEXT_PCB_THICKNESS;    // current Pcb (not module) Text width
80

81 82
    m_PcbTextSize       = wxSize( DEFAULT_TEXT_PCB_SIZE,
                                  DEFAULT_TEXT_PCB_SIZE );  // current Pcb (not module) Text size
83 84 85 86 87 88

    m_TrackMinWidth     = DMils2iu( 100 );      // track min value for width ((min copper size value
    m_ViasMinSize       = DMils2iu( 350 );      // vias (not micro vias) min diameter
    m_ViasMinDrill      = DMils2iu( 200 );      // vias (not micro vias) min drill diameter
    m_MicroViasMinSize  = DMils2iu( 200 );      // micro vias (not vias) min diameter
    m_MicroViasMinDrill = DMils2iu( 50 );       // micro vias (not vias) min drill diameter
89

90
    // Global mask margins:
91 92
    m_SolderMaskMargin  = DEFAULT_SOLDERMASK_CLEARANCE; // Solder mask margin
    m_SolderMaskMinWidth = DEFAULT_SOLDERMASK_MIN_WIDTH;   // Solder mask min width
93 94 95 96
    m_SolderPasteMargin = 0;                    // Solder paste margin absolute value
    m_SolderPasteMarginRatio = 0.0;             // Solder pask margin ratio value of pad size
                                                // The final margin is the sum of these 2 values
                                                // Usually < 0 because the mask is smaller than pad
charras's avatar
charras committed
97

98 99 100 101
    m_ModuleTextSize = wxSize( DEFAULT_TEXT_MODULE_SIZE,
                               DEFAULT_TEXT_MODULE_SIZE );
    m_ModuleTextWidth = DEFAULT_GR_MODULE_THICKNESS;
    m_ModuleSegmentWidth = DEFAULT_GR_MODULE_THICKNESS;
102

103
    // Layer thickness for 3D viewer
104
    m_boardThickness = Millimeter2iu( DEFAULT_BOARD_THICKNESS_MM );
charras's avatar
charras committed
105 106
}

107 108
// Add parameters to save in project config.
// values are saved in mm
Dick Hollenbeck's avatar
Dick Hollenbeck committed
109 110 111 112
void BOARD_DESIGN_SETTINGS::AppendConfigs( PARAM_CFG_ARRAY* aResult )
{
    m_Pad_Master.AppendConfigs( aResult );

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PcbTextSizeV" ),
                    &m_PcbTextSize.y,
                    DEFAULT_TEXT_PCB_SIZE, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PcbTextSizeH" ),
                    &m_PcbTextSize.x,
                    DEFAULT_TEXT_PCB_SIZE, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PcbTextThickness" ),
                    &m_PcbTextWidth,
                    DEFAULT_TEXT_PCB_THICKNESS,
                    Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "ModuleTextSizeV" ),
                    &m_ModuleTextSize.y,
                    DEFAULT_TEXT_MODULE_SIZE, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "ModuleTextSizeH" ),
                    &m_ModuleTextSize.x,
                    DEFAULT_TEXT_MODULE_SIZE, TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "ModuleTextSizeThickness" ),
                    &m_ModuleTextWidth,
                    DEFAULT_GR_MODULE_THICKNESS, 1, TEXTS_MAX_WIDTH,
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SolderMaskClearance" ),
                    &m_SolderMaskMargin,
                    DEFAULT_SOLDERMASK_CLEARANCE, 0, Millimeter2iu( 1.0 ),
                    NULL, MM_PER_IU ) );

149 150 151 152 153
    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SolderMaskMinWidth" ),
                    &m_SolderMaskMinWidth,
                    DEFAULT_SOLDERMASK_MIN_WIDTH, 0, Millimeter2iu( 0.5 ),
                    NULL, MM_PER_IU ) );

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "DrawSegmentWidth" ),
                    &m_DrawSegmentWidth,
                    DEFAULT_GRAPHIC_THICKNESS,
                    Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "BoardOutlineThickness" ),
                    &m_EdgeSegmentWidth,
                    DEFAULT_PCB_EDGE_THICKNESS,
                    Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "ModuleOutlineThickness" ),
                    &m_ModuleSegmentWidth,
                    DEFAULT_GR_MODULE_THICKNESS,
                    Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
                    NULL, MM_PER_IU ) );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
171 172 173
}


charras's avatar
charras committed
174
// see pcbstruct.h
175
LAYER_MSK BOARD_DESIGN_SETTINGS::GetVisibleLayers() const
charras's avatar
charras committed
176 177 178 179
{
    return m_VisibleLayers;
}

180

181
void BOARD_DESIGN_SETTINGS::SetVisibleAlls()
182 183
{
    SetVisibleLayers( FULL_LAYERS );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
184
    m_VisibleElements = -1;
185 186
}

187

188
void BOARD_DESIGN_SETTINGS::SetVisibleLayers( LAYER_MSK aMask )
charras's avatar
charras committed
189
{
190
    m_VisibleLayers = aMask & m_EnabledLayers & FULL_LAYERS;
charras's avatar
charras committed
191 192
}

193

194
void BOARD_DESIGN_SETTINGS::SetLayerVisibility( LAYER_NUM aLayer, bool aNewState )
charras's avatar
charras committed
195
{
196 197
    if( aNewState && IsLayerEnabled( aLayer ) )
        m_VisibleLayers |= GetLayerMask( aLayer );
charras's avatar
charras committed
198
    else
199
        m_VisibleLayers &= ~GetLayerMask( aLayer );
charras's avatar
charras committed
200 201
}

202

203
void BOARD_DESIGN_SETTINGS::SetElementVisibility( int aElementCategory, bool aNewState )
charras's avatar
charras committed
204
{
205
    if( aElementCategory < 0 || aElementCategory >= END_PCB_VISIBLE_LIST )
charras's avatar
charras committed
206
        return;
207

charras's avatar
charras committed
208 209 210 211 212
    if( aNewState )
        m_VisibleElements |= 1 << aElementCategory;
    else
        m_VisibleElements &= ~( 1 << aElementCategory );
}
213 214


215
void BOARD_DESIGN_SETTINGS::SetCopperLayerCount( int aNewLayerCount )
charras's avatar
charras committed
216
{
217 218
    // if( aNewLayerCount < 2 ) aNewLayerCount = 2;

charras's avatar
charras committed
219
    m_CopperLayerCount = aNewLayerCount;
220

charras's avatar
charras committed
221 222
    // ensure consistency with the m_EnabledLayers member
    m_EnabledLayers &= ~ALL_CU_LAYERS;
223
    m_EnabledLayers |= LAYER_BACK;
dickelbeck's avatar
dickelbeck committed
224

225
    if( m_CopperLayerCount > 1 )
226
        m_EnabledLayers |= LAYER_FRONT;
dickelbeck's avatar
dickelbeck committed
227

228
    for( LAYER_NUM ii = LAYER_N_2; ii < aNewLayerCount - 1; ++ii )
229
        m_EnabledLayers |= GetLayerMask( ii );
charras's avatar
charras committed
230
}
dickelbeck's avatar
dickelbeck committed
231

232

233
void BOARD_DESIGN_SETTINGS::SetEnabledLayers( LAYER_MSK aMask )
234
{
235 236 237
    // Back and front layers are always enabled.
    aMask |= LAYER_BACK | LAYER_FRONT;

238 239
    m_EnabledLayers = aMask;

240 241
    // A disabled layer cannot be visible
    m_VisibleLayers &= aMask;
242

243
    // update m_CopperLayerCount to ensure its consistency with m_EnabledLayers
244
    m_CopperLayerCount = LayerMaskCountSet( aMask & ALL_CU_LAYERS);
245
}