2013-02-12 01:07:04 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file class_board_design_settings.cpp
|
|
|
|
* BOARD_DESIGN_SETTINGS class functions.
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2009-10-28 11:48:47 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board_design_settings.h>
|
2009-10-28 11:48:47 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_track.h>
|
2012-10-17 10:57:21 +00:00
|
|
|
#include <convert_from_iu.h>
|
2009-10-28 11:48:47 +00:00
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
// 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 )
|
|
|
|
|
2012-11-12 16:19:10 +00:00
|
|
|
#define DEFAULT_SOLDERMASK_CLEARANCE Millimeter2iu( 0.2 )
|
2012-11-05 20:20:34 +00:00
|
|
|
#define DEFAULT_SOLDERMASK_MIN_WIDTH Millimeter2iu( 0.0 )
|
2012-04-08 23:32:32 +00:00
|
|
|
|
2009-10-28 11:48:47 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS() :
|
BOARD_CONNECTED_ITEMs do not store net code anymore (m_NetCode field), instead net info is stored using a pointer to NETINFO_ITEM.
GetNet() refers to the net code stored in the NETINFO_ITEM. SetNet() finds an appropriate NETINFO_ITEM and uses it.
Removing GetNet() & SetNet() (and the whole net code idea) requires too many changes in the code (~250 references to the mentioned functions).
BOARD_CONNECTED_ITEMs by default get a pointer to NETINFO_ITEM that stores unconnected items. This requires for all BOARD_CONNECTED_ITEMs to have a parent (so BOARD* is accessible). The only orphaned item is BOARD_DESIGN_SETTINGS::m_Pad_Master, but it does not cause any issues so far.
Items that do not have access to a BOARD (do not have set parents) and therefore cannot get net assigned, by default get const static NETINFO_LIST::ORPHANED.
Performed tests:
- loaded .kicad_pcb, KiCad legacy board, Eagle 6.0 board, P-CAD board - all ok
- load a simple project, reload netlist after changing connections in eeschema - ok
- save & reload a board - ok, but still contain empty nets
- remove everything, restore with undo - ok
- remove everything, reload netlist - ok
- changing net names (all possibilites: empty->existing, empty->not existing, existing->empty, existing->not existing) - all ok
- zones: when net is changed to a net that does not have any nodes besides the zone itself, it does not get filled
2014-01-15 17:03:06 +00:00
|
|
|
m_Pad_Master( NULL )
|
2009-10-28 11:48:47 +00:00
|
|
|
{
|
2011-09-23 13:57:12 +00:00
|
|
|
m_EnabledLayers = ALL_LAYERS; // All layers enabled at first.
|
|
|
|
// SetCopperLayerCount() will adjust this.
|
2012-02-06 05:44:19 +00:00
|
|
|
|
|
|
|
SetVisibleLayers( FULL_LAYERS );
|
|
|
|
|
|
|
|
// set all but hidden text as visible.
|
2012-02-06 15:31:36 +00:00
|
|
|
m_VisibleElements = ~( 1 << MOD_TEXT_INVISIBLE );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-08-28 16:14:39 +00:00
|
|
|
m_BlindBuriedViaAllowed = false; // true to allow blind/buried vias
|
2011-09-23 13:57:12 +00:00
|
|
|
m_MicroViasAllowed = false; // true to allow micro vias
|
2012-04-08 23:32:32 +00:00
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
m_DrawSegmentWidth = DEFAULT_GRAPHIC_THICKNESS; // current graphic line width (not EDGE layer)
|
2012-04-08 23:32:32 +00:00
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
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
|
2012-04-08 23:32:32 +00:00
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
m_PcbTextSize = wxSize( DEFAULT_TEXT_PCB_SIZE,
|
|
|
|
DEFAULT_TEXT_PCB_SIZE ); // current Pcb (not module) Text size
|
2012-04-08 23:32:32 +00:00
|
|
|
|
|
|
|
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
|
2009-12-07 06:16:11 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
// Global mask margins:
|
2012-11-05 20:20:34 +00:00
|
|
|
m_SolderMaskMargin = DEFAULT_SOLDERMASK_CLEARANCE; // Solder mask margin
|
|
|
|
m_SolderMaskMinWidth = DEFAULT_SOLDERMASK_MIN_WIDTH; // Solder mask min width
|
2011-09-23 13:57:12 +00:00
|
|
|
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
|
2009-10-28 11:48:47 +00:00
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
m_ModuleTextSize = wxSize( DEFAULT_TEXT_MODULE_SIZE,
|
|
|
|
DEFAULT_TEXT_MODULE_SIZE );
|
|
|
|
m_ModuleTextWidth = DEFAULT_GR_MODULE_THICKNESS;
|
|
|
|
m_ModuleSegmentWidth = DEFAULT_GR_MODULE_THICKNESS;
|
2012-02-02 07:23:00 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
// Layer thickness for 3D viewer
|
2012-10-17 10:57:21 +00:00
|
|
|
m_boardThickness = Millimeter2iu( DEFAULT_BOARD_THICKNESS_MM );
|
2009-10-28 11:48:47 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
// Add parameters to save in project config.
|
|
|
|
// values are saved in mm
|
2012-02-19 04:02:19 +00:00
|
|
|
void BOARD_DESIGN_SETTINGS::AppendConfigs( PARAM_CFG_ARRAY* aResult )
|
|
|
|
{
|
|
|
|
m_Pad_Master.AppendConfigs( aResult );
|
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
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 ) );
|
|
|
|
|
2012-11-05 20:20:34 +00:00
|
|
|
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 ) );
|
|
|
|
|
2012-10-17 10:57:21 +00:00
|
|
|
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 ) );
|
2012-02-19 04:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-28 11:48:47 +00:00
|
|
|
// see pcbstruct.h
|
2013-03-30 17:24:04 +00:00
|
|
|
LAYER_MSK BOARD_DESIGN_SETTINGS::GetVisibleLayers() const
|
2009-10-28 11:48:47 +00:00
|
|
|
{
|
|
|
|
return m_VisibleLayers;
|
|
|
|
}
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
void BOARD_DESIGN_SETTINGS::SetVisibleAlls()
|
2010-01-27 20:07:50 +00:00
|
|
|
{
|
|
|
|
SetVisibleLayers( FULL_LAYERS );
|
2012-02-06 07:14:51 +00:00
|
|
|
m_VisibleElements = -1;
|
2010-01-27 20:07:50 +00:00
|
|
|
}
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2013-03-30 17:24:04 +00:00
|
|
|
void BOARD_DESIGN_SETTINGS::SetVisibleLayers( LAYER_MSK aMask )
|
2009-10-28 11:48:47 +00:00
|
|
|
{
|
2009-11-09 15:55:18 +00:00
|
|
|
m_VisibleLayers = aMask & m_EnabledLayers & FULL_LAYERS;
|
2009-10-28 11:48:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2013-04-09 16:00:46 +00:00
|
|
|
void BOARD_DESIGN_SETTINGS::SetLayerVisibility( LAYER_NUM aLayer, bool aNewState )
|
2009-10-28 11:48:47 +00:00
|
|
|
{
|
2013-04-09 16:00:46 +00:00
|
|
|
if( aNewState && IsLayerEnabled( aLayer ) )
|
|
|
|
m_VisibleLayers |= GetLayerMask( aLayer );
|
2009-10-28 11:48:47 +00:00
|
|
|
else
|
2013-04-09 16:00:46 +00:00
|
|
|
m_VisibleLayers &= ~GetLayerMask( aLayer );
|
2009-10-28 11:48:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
void BOARD_DESIGN_SETTINGS::SetElementVisibility( int aElementCategory, bool aNewState )
|
2009-10-28 11:48:47 +00:00
|
|
|
{
|
2010-01-29 20:36:12 +00:00
|
|
|
if( aElementCategory < 0 || aElementCategory >= END_PCB_VISIBLE_LIST )
|
2009-10-28 11:48:47 +00:00
|
|
|
return;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-10-28 11:48:47 +00:00
|
|
|
if( aNewState )
|
|
|
|
m_VisibleElements |= 1 << aElementCategory;
|
|
|
|
else
|
|
|
|
m_VisibleElements &= ~( 1 << aElementCategory );
|
|
|
|
}
|
2009-11-04 19:08:08 +00:00
|
|
|
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
void BOARD_DESIGN_SETTINGS::SetCopperLayerCount( int aNewLayerCount )
|
2009-10-28 11:48:47 +00:00
|
|
|
{
|
2010-01-21 07:41:30 +00:00
|
|
|
// if( aNewLayerCount < 2 ) aNewLayerCount = 2;
|
|
|
|
|
2009-10-28 11:48:47 +00:00
|
|
|
m_CopperLayerCount = aNewLayerCount;
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2009-10-28 11:48:47 +00:00
|
|
|
// ensure consistency with the m_EnabledLayers member
|
|
|
|
m_EnabledLayers &= ~ALL_CU_LAYERS;
|
2009-12-21 12:05:36 +00:00
|
|
|
m_EnabledLayers |= LAYER_BACK;
|
2009-12-07 03:46:13 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
if( m_CopperLayerCount > 1 )
|
2009-12-21 12:05:36 +00:00
|
|
|
m_EnabledLayers |= LAYER_FRONT;
|
2009-12-07 03:46:13 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
for( LAYER_NUM ii = LAYER_N_2; ii < aNewLayerCount - 1; ++ii )
|
2013-03-30 17:24:04 +00:00
|
|
|
m_EnabledLayers |= GetLayerMask( ii );
|
2009-10-28 11:48:47 +00:00
|
|
|
}
|
2009-12-07 03:46:13 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2013-03-30 17:24:04 +00:00
|
|
|
void BOARD_DESIGN_SETTINGS::SetEnabledLayers( LAYER_MSK aMask )
|
2009-12-21 12:05:36 +00:00
|
|
|
{
|
2010-01-21 07:41:30 +00:00
|
|
|
// Back and front layers are always enabled.
|
|
|
|
aMask |= LAYER_BACK | LAYER_FRONT;
|
|
|
|
|
2009-12-21 12:05:36 +00:00
|
|
|
m_EnabledLayers = aMask;
|
|
|
|
|
2010-01-21 07:41:30 +00:00
|
|
|
// A disabled layer cannot be visible
|
|
|
|
m_VisibleLayers &= aMask;
|
2009-12-21 12:05:36 +00:00
|
|
|
|
2010-01-21 07:41:30 +00:00
|
|
|
// update m_CopperLayerCount to ensure its consistency with m_EnabledLayers
|
2013-04-09 16:00:46 +00:00
|
|
|
m_CopperLayerCount = LayerMaskCountSet( aMask & ALL_CU_LAYERS);
|
2009-12-21 12:05:36 +00:00
|
|
|
}
|
2014-02-07 19:54:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
struct static_check {
|
|
|
|
static_check()
|
|
|
|
{
|
|
|
|
// 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 );
|
|
|
|
};
|
|
|
|
};
|
|
|
|
static static_check check;
|
|
|
|
#endif
|