class_board_design_settings.cpp 13.3 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4
 * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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


Dick Hollenbeck's avatar
Dick Hollenbeck committed
40
BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() :
41
    m_Pad_Master( NULL )
charras's avatar
charras committed
42
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
43
    LSET    all_set = LSET().set();
Dick Hollenbeck's avatar
Dick Hollenbeck committed
44

45 46
    m_enabledLayers = all_set;              // All layers enabled at first.
                                            // SetCopperLayerCount() will adjust this.
Dick Hollenbeck's avatar
Dick Hollenbeck committed
47
    SetVisibleLayers( all_set );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
48 49

    // set all but hidden text as visible.
50
    m_visibleElements = ~( 1 << MOD_TEXT_INVISIBLE );
51

52
    SetCopperLayerCount( 2 );               // Default design is a double sided board
53 54 55 56 57 58 59

    // 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;

60
    m_BlindBuriedViaAllowed = false;            // true to allow blind/buried vias
61
    m_MicroViasAllowed = false;                 // true to allow micro vias
62

63
    m_DrawSegmentWidth = Millimeter2iu( DEFAULT_GRAPHIC_THICKNESS );     // current graphic line width (not EDGE layer)
64

65 66
    m_EdgeSegmentWidth = Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS );    // current graphic line width (EDGE layer only)
    m_PcbTextWidth     = Millimeter2iu(DEFAULT_TEXT_PCB_THICKNESS );    // current Pcb (not module) Text width
67

68 69
    m_PcbTextSize       = wxSize( Millimeter2iu( DEFAULT_TEXT_PCB_SIZE  ),
                                  Millimeter2iu( DEFAULT_TEXT_PCB_SIZE  ) );  // current Pcb (not module) Text size
70

71
    m_useCustomTrackVia = false;
72 73 74 75 76 77
    m_customTrackWidth  = Millimeter2iu( DEFAULT_CUSTOMTRACKWIDTH );
    m_TrackMinWidth     = Millimeter2iu( DEFAULT_TRACKMINWIDTH );   // track min width
    m_ViasMinSize       = Millimeter2iu( DEFAULT_VIASMINSIZE );     // via (not uvia) min diam
    m_ViasMinDrill      = Millimeter2iu( DEFAULT_VIASMINDRILL );    // via (not uvia) min drill diam
    m_MicroViasMinSize  = Millimeter2iu( DEFAULT_MICROVIASMINSIZE );// uvia (not via) min diam
    m_MicroViasMinDrill = Millimeter2iu( DEFAULT_MICROVIASMINDRILL );// uvia (not via) min drill diam
78

79
    // Global mask margins:
80 81
    m_SolderMaskMargin  = Millimeter2iu( DEFAULT_SOLDERMASK_CLEARANCE ); // Solder mask margin
    m_SolderMaskMinWidth = Millimeter2iu( DEFAULT_SOLDERMASK_MIN_WIDTH );   // Solder mask min width
82 83 84 85
    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
86

87
    // Layer thickness for 3D viewer
88
    m_boardThickness = Millimeter2iu( DEFAULT_BOARD_THICKNESS_MM );
89 90 91

    m_viaSizeIndex = 0;
    m_trackWidthIndex = 0;
92 93 94

    // Default values for the footprint editor and fp creation
    // (also covers footprints created on the fly by micor-waves tools)
95 96 97 98
    m_ModuleTextSize = wxSize( Millimeter2iu( DEFAULT_TEXT_MODULE_SIZE ),
                               Millimeter2iu( DEFAULT_TEXT_MODULE_SIZE ) );
    m_ModuleTextWidth = Millimeter2iu( DEFAULT_GR_MODULE_THICKNESS );
    m_ModuleSegmentWidth = Millimeter2iu( DEFAULT_GR_MODULE_THICKNESS );
99 100 101 102 103 104 105 106 107 108

    // These values will be overriden by config values after reading the config
    // Default ref text on fp creation. if empty, use footprint name as default
    m_RefDefaultText = wxT( "REF**" );
    m_RefDefaultVisibility = true;          // Default ref text visibility on fp creation
    m_RefDefaultlayer = int( F_SilkS );     // Default ref text layer on fp creation
    // Default value text on fp creation. if empty, use footprint name as default
    m_ValueDefaultText = wxEmptyString;
    m_ValueDefaultVisibility = true;
    m_ValueDefaultlayer = int( F_Fab );
charras's avatar
charras committed
109 110
}

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

117 118
    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PcbTextSizeV" ),
                    &m_PcbTextSize.y,
119
                    Millimeter2iu( DEFAULT_TEXT_PCB_SIZE  ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
120 121 122 123
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PcbTextSizeH" ),
                    &m_PcbTextSize.x,
124
                    Millimeter2iu( DEFAULT_TEXT_PCB_SIZE  ), TEXTS_MIN_SIZE, TEXTS_MAX_SIZE,
125 126 127 128
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PcbTextThickness" ),
                    &m_PcbTextWidth,
129
                    Millimeter2iu(DEFAULT_TEXT_PCB_THICKNESS ),
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
                    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,
145
                    Millimeter2iu( DEFAULT_GR_MODULE_THICKNESS ), 1, TEXTS_MAX_WIDTH,
146 147 148 149
                    NULL, MM_PER_IU ) );

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

153 154
    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "SolderMaskMinWidth" ),
                    &m_SolderMaskMinWidth,
155
                    Millimeter2iu( DEFAULT_SOLDERMASK_MIN_WIDTH ), 0, Millimeter2iu( 0.5 ),
156 157
                    NULL, MM_PER_IU ) );

158 159
    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "DrawSegmentWidth" ),
                    &m_DrawSegmentWidth,
160
                    Millimeter2iu( DEFAULT_GRAPHIC_THICKNESS ),
161 162 163 164 165
                    Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
                    NULL, MM_PER_IU ) );

    aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "BoardOutlineThickness" ),
                    &m_EdgeSegmentWidth,
166
                    Millimeter2iu( DEFAULT_PCB_EDGE_THICKNESS ),
167 168 169 170 171
                    Millimeter2iu( 0.01 ), Millimeter2iu( 5.0 ),
                    NULL, MM_PER_IU ) );

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


178 179
bool BOARD_DESIGN_SETTINGS::SetCurrentNetClass( const wxString& aNetClassName )
{
180 181
    NETCLASSPTR netClass = m_NetClasses.Find( aNetClassName );
    bool        lists_sizes_modified = false;
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

    // if not found (should not happen) use the default
    if( netClass == NULL )
        netClass = m_NetClasses.GetDefault();

    m_currentNetClassName = netClass->GetName();

    // Initialize others values:
    if( m_ViasDimensionsList.size() == 0 )
    {
        VIA_DIMENSION viadim;
        lists_sizes_modified = true;
        m_ViasDimensionsList.push_back( viadim );
    }

    if( m_TrackWidthList.size() == 0 )
    {
        lists_sizes_modified = true;
        m_TrackWidthList.push_back( 0 );
    }

    /* note the m_ViasDimensionsList[0] and m_TrackWidthList[0] values
     * are always the Netclass values
     */
    if( m_ViasDimensionsList[0].m_Diameter != netClass->GetViaDiameter() )
        lists_sizes_modified = true;

    m_ViasDimensionsList[0].m_Diameter = netClass->GetViaDiameter();

    if( m_TrackWidthList[0] != netClass->GetTrackWidth() )
        lists_sizes_modified = true;

    m_TrackWidthList[0] = netClass->GetTrackWidth();

    if( GetViaSizeIndex() >= m_ViasDimensionsList.size() )
        SetViaSizeIndex( m_ViasDimensionsList.size() );

    if( GetTrackWidthIndex() >= m_TrackWidthList.size() )
        SetTrackWidthIndex( m_TrackWidthList.size() );

    return lists_sizes_modified;
}


int BOARD_DESIGN_SETTINGS::GetBiggestClearanceValue()
{
    int clearance = m_NetClasses.GetDefault()->GetClearance();

    //Read list of Net Classes
231
    for( NETCLASSES::const_iterator nc = m_NetClasses.begin(); nc != m_NetClasses.end(); ++nc )
232
    {
233
        NETCLASSPTR netclass = nc->second;
234 235 236 237 238 239 240 241 242 243 244 245
        clearance = std::max( clearance, netclass->GetClearance() );
    }

    return clearance;
}


int BOARD_DESIGN_SETTINGS::GetSmallestClearanceValue()
{
    int clearance = m_NetClasses.GetDefault()->GetClearance();

    //Read list of Net Classes
246
    for( NETCLASSES::const_iterator nc = m_NetClasses.begin(); nc != m_NetClasses.end(); ++nc )
247
    {
248
        NETCLASSPTR netclass = nc->second;
249 250 251 252 253 254 255 256 257
        clearance = std::min( clearance, netclass->GetClearance() );
    }

    return clearance;
}


int BOARD_DESIGN_SETTINGS::GetCurrentMicroViaSize()
{
258
    NETCLASSPTR netclass = m_NetClasses.Find( m_currentNetClassName );
259 260 261 262 263 264 265

    return netclass->GetuViaDiameter();
}


int BOARD_DESIGN_SETTINGS::GetCurrentMicroViaDrill()
{
266
    NETCLASSPTR netclass = m_NetClasses.Find( m_currentNetClassName );
267 268 269 270 271

    return netclass->GetuViaDrill();
}


272 273 274 275 276 277
void BOARD_DESIGN_SETTINGS::SetViaSizeIndex( unsigned aIndex )
{
    if( aIndex >= m_ViasDimensionsList.size() )
        m_viaSizeIndex = m_ViasDimensionsList.size();
    else
        m_viaSizeIndex = aIndex;
278 279

    m_useCustomTrackVia = false;
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
}


int BOARD_DESIGN_SETTINGS::GetCurrentViaDrill() const
{
    int drill;

    if( m_useCustomTrackVia )
        drill = m_customViaSize.m_Drill;
    else
        drill = m_ViasDimensionsList[m_viaSizeIndex].m_Drill;

    return drill > 0 ? drill : -1;
}


void BOARD_DESIGN_SETTINGS::SetTrackWidthIndex( unsigned aIndex )
{
    if( aIndex >= m_TrackWidthList.size() )
        m_trackWidthIndex = m_TrackWidthList.size();
    else
        m_trackWidthIndex = aIndex;
302 303

    m_useCustomTrackVia = false;
304 305 306
}


307
void BOARD_DESIGN_SETTINGS::SetVisibleAlls()
308
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
309
    SetVisibleLayers( LSET().set() );
310
    m_visibleElements = -1;
charras's avatar
charras committed
311 312
}

313

Dick Hollenbeck's avatar
Dick Hollenbeck committed
314
void BOARD_DESIGN_SETTINGS::SetLayerVisibility( LAYER_ID aLayer, bool aNewState )
charras's avatar
charras committed
315
{
316
    if( aNewState && IsLayerEnabled( aLayer ) )
Dick Hollenbeck's avatar
Dick Hollenbeck committed
317
        m_visibleLayers.set( aLayer, true );
charras's avatar
charras committed
318
    else
Dick Hollenbeck's avatar
Dick Hollenbeck committed
319
        m_visibleLayers.set( aLayer, false );
charras's avatar
charras committed
320 321
}

322

323
void BOARD_DESIGN_SETTINGS::SetElementVisibility( int aElementCategory, bool aNewState )
charras's avatar
charras committed
324
{
325
    if( aElementCategory < 0 || aElementCategory >= END_PCB_VISIBLE_LIST )
charras's avatar
charras committed
326
        return;
327

charras's avatar
charras committed
328
    if( aNewState )
329
        m_visibleElements |= 1 << aElementCategory;
charras's avatar
charras committed
330
    else
331
        m_visibleElements &= ~( 1 << aElementCategory );
charras's avatar
charras committed
332
}
333 334


335
void BOARD_DESIGN_SETTINGS::SetCopperLayerCount( int aNewLayerCount )
charras's avatar
charras committed
336
{
337 338
    // if( aNewLayerCount < 2 ) aNewLayerCount = 2;

339
    m_copperLayerCount = aNewLayerCount;
340

charras's avatar
charras committed
341
    // ensure consistency with the m_EnabledLayers member
Dick Hollenbeck's avatar
Dick Hollenbeck committed
342 343
#if 0
    // was:
344 345
    m_enabledLayers &= ~ALL_CU_LAYERS;
    m_enabledLayers |= LAYER_BACK;
dickelbeck's avatar
dickelbeck committed
346

347 348
    if( m_copperLayerCount > 1 )
        m_enabledLayers |= LAYER_FRONT;
dickelbeck's avatar
dickelbeck committed
349

350
    for( LAYER_NUM ii = LAYER_N_2; ii < aNewLayerCount - 1; ++ii )
Dick Hollenbeck's avatar
Dick Hollenbeck committed
351 352
        m_enabledLayers |= GetLayerSet( ii );
#else
353 354 355
    // Update only enabled copper layers mask
    m_enabledLayers &= ~LSET::AllCuMask();
    m_enabledLayers |= LSET::AllCuMask( aNewLayerCount );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
356
#endif
charras's avatar
charras committed
357
}
dickelbeck's avatar
dickelbeck committed
358

359

Dick Hollenbeck's avatar
Dick Hollenbeck committed
360
void BOARD_DESIGN_SETTINGS::SetEnabledLayers( LSET aMask )
361
{
362
    // Back and front layers are always enabled.
Dick Hollenbeck's avatar
Dick Hollenbeck committed
363
    aMask.set( B_Cu ).set( F_Cu );
364

365
    m_enabledLayers = aMask;
366

367
    // A disabled layer cannot be visible
368
    m_visibleLayers &= aMask;
369

370
    // update m_CopperLayerCount to ensure its consistency with m_EnabledLayers
Dick Hollenbeck's avatar
Dick Hollenbeck committed
371
    m_copperLayerCount = ( aMask & LSET::AllCuMask() ).count();
372
}
373 374 375


#ifndef NDEBUG
376 377
struct list_size_check {
   list_size_check()
378 379 380 381 382 383
   {
       // Int (the type used for saving visibility settings) is only 32 bits guaranteed,
       // be sure that we do not cross the limit
       assert( END_PCB_VISIBLE_LIST <= 32 );
   };
};
384
static list_size_check check;
385
#endif