2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-10-05 18:11:55 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
2017-10-05 18:11:55 +00:00
|
|
|
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-17 20:01:27 +00:00
|
|
|
*
|
|
|
|
* 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_pad_draw_functions.cpp
|
|
|
|
*/
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <trigo.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <pcb_screen.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_drawpanel.h>
|
2018-01-28 21:02:31 +00:00
|
|
|
#include <draw_graphic_text.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew_id.h> // ID_TRACK_BUTT
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board.h>
|
2016-04-06 18:15:49 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
|
2010-03-29 16:42:03 +00:00
|
|
|
/* uncomment this line to show this pad with its specfic size and color
|
|
|
|
* when it is not on copper layers, and only one solder mask layer or solder paste layer
|
|
|
|
* is displayed for this pad
|
|
|
|
* After testing this feature,I am not sure this is a good idea
|
|
|
|
* but the code is left here.
|
|
|
|
*/
|
2010-09-11 16:33:43 +00:00
|
|
|
|
2010-03-29 16:42:03 +00:00
|
|
|
//#define SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
|
|
|
|
// Helper class to store parameters used to draw a pad
|
2010-09-11 19:15:24 +00:00
|
|
|
PAD_DRAWINFO::PAD_DRAWINFO()
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
2010-09-11 19:15:24 +00:00
|
|
|
m_DrawPanel = NULL;
|
2012-09-01 13:38:27 +00:00
|
|
|
m_DrawMode = GR_COPY;
|
2010-09-11 19:15:24 +00:00
|
|
|
m_Color = BLACK;
|
|
|
|
m_HoleColor = BLACK; // could be DARKGRAY;
|
2011-08-19 13:08:24 +00:00
|
|
|
m_NPHoleColor = YELLOW;
|
2017-10-05 18:11:55 +00:00
|
|
|
m_NoNetMarkColor = BLUE;
|
2010-09-11 19:15:24 +00:00
|
|
|
m_PadClearance = 0;
|
|
|
|
m_Display_padnum = true;
|
2010-09-11 16:33:43 +00:00
|
|
|
m_Display_netname = true;
|
2010-09-11 19:15:24 +00:00
|
|
|
m_ShowPadFilled = true;
|
|
|
|
m_ShowNCMark = true;
|
2011-08-19 13:08:24 +00:00
|
|
|
m_ShowNotPlatedHole = false;
|
2010-09-11 16:33:43 +00:00
|
|
|
m_IsPrinting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-01 13:38:27 +00:00
|
|
|
void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDraw_mode,
|
|
|
|
const wxPoint& aOffset )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-11 19:15:24 +00:00
|
|
|
wxSize mask_margin; // margin (clearance) used for some non copper layers
|
2011-05-13 13:15:28 +00:00
|
|
|
|
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
2011-10-17 20:01:27 +00:00
|
|
|
int showActualMaskSize = 0; /* Layer number if the actual pad size on mask layer can
|
|
|
|
* be displayed i.e. if only one layer is shown for this pad
|
2013-04-07 16:20:46 +00:00
|
|
|
* and this layer is a mask (solder mask or solder paste
|
2010-09-11 16:33:43 +00:00
|
|
|
*/
|
2011-05-13 13:15:28 +00:00
|
|
|
#endif
|
2008-12-14 19:45:05 +00:00
|
|
|
|
|
|
|
if( m_Flags & DO_NOT_DRAW )
|
|
|
|
return;
|
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
PAD_DRAWINFO drawInfo;
|
|
|
|
|
|
|
|
drawInfo.m_Offset = aOffset;
|
|
|
|
|
2010-01-26 18:02:03 +00:00
|
|
|
/* We can show/hide pads from the layer manager.
|
2010-09-11 16:33:43 +00:00
|
|
|
* options are show/hide pads on front and/or back side of the board
|
|
|
|
* For through pads, we hide them only if both sides are hidden.
|
|
|
|
* smd pads on back are hidden for all layers (copper and technical layers)
|
|
|
|
* on back side of the board
|
|
|
|
* smd pads on front are hidden for all layers (copper and technical layers)
|
|
|
|
* on front side of the board
|
|
|
|
* ECO, edge and Draw layers and not considered
|
|
|
|
*/
|
2010-01-26 18:02:03 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
BOARD* brd = GetBoard();
|
2017-08-04 12:43:02 +00:00
|
|
|
|
|
|
|
auto frame = static_cast<PCB_EDIT_FRAME*> ( aPanel->GetParent() );
|
|
|
|
const auto& cds = frame->Settings().Colors();
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
bool frontVisible = brd->IsElementVisible( LAYER_PAD_FR );
|
|
|
|
bool backVisible = brd->IsElementVisible( LAYER_PAD_BK );
|
2010-01-26 18:02:03 +00:00
|
|
|
|
|
|
|
if( !frontVisible && !backVisible )
|
|
|
|
return;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
// If pad is only on front side (no layer on back side)
|
|
|
|
// and if hide front side pads is enabled, do not draw
|
|
|
|
if( !frontVisible && !( m_layerMask & LSET::BackMask() ).any() )
|
2010-01-26 18:02:03 +00:00
|
|
|
return;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
// If pad is only on back side (no layer on front side)
|
|
|
|
// and if hide back side pads is enabled, do not draw
|
|
|
|
if( !backVisible && !( m_layerMask & LSET::FrontMask() ).any() )
|
2010-01-26 18:02:03 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-28 20:50:35 +00:00
|
|
|
|
|
|
|
wxCHECK_RET( frame != NULL, wxT( "Panel has no parent frame window." ) );
|
|
|
|
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( frame->GetDisplayOptions() );
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_SCREEN* screen = frame->GetScreen();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2015-02-22 09:39:58 +00:00
|
|
|
if( displ_opts && displ_opts->m_DisplayPadFill == SKETCH )
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_ShowPadFilled = false;
|
2015-02-22 09:39:58 +00:00
|
|
|
else
|
|
|
|
drawInfo.m_ShowPadFilled = true;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
COLOR4D color = COLOR4D::BLACK;
|
2015-02-28 20:50:35 +00:00
|
|
|
|
2014-08-02 10:29:10 +00:00
|
|
|
if( m_layerMask[F_Cu] )
|
2010-01-26 18:02:03 +00:00
|
|
|
{
|
2017-08-04 12:43:02 +00:00
|
|
|
color = cds.GetItemColor( LAYER_PAD_FR );
|
2010-01-26 18:02:03 +00:00
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2014-08-02 10:29:10 +00:00
|
|
|
if( m_layerMask[B_Cu] )
|
2010-01-26 18:02:03 +00:00
|
|
|
{
|
2017-08-04 12:43:02 +00:00
|
|
|
color = color.LegacyMix( cds.GetItemColor( LAYER_PAD_BK ) );
|
2010-01-26 18:02:03 +00:00
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
if( color == BLACK ) // Not on a visible copper layer (i.e. still nothing to show)
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2013-04-04 21:35:01 +00:00
|
|
|
// If the pad is on only one tech layer, use the layer color else use DARKGRAY
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET mask_non_copper_layers = m_layerMask & ~LSET::AllCuMask();
|
|
|
|
|
2010-03-29 16:42:03 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
|
|
|
mask_non_copper_layers &= brd->GetVisibleLayers();
|
|
|
|
#endif
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID pad_layer = mask_non_copper_layers.ExtractLayer();
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
switch( (int) pad_layer )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2013-04-05 19:04:58 +00:00
|
|
|
case UNDEFINED_LAYER: // More than one layer
|
|
|
|
color = DARKGRAY;
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2013-04-05 19:04:58 +00:00
|
|
|
case UNSELECTED_LAYER: // Shouldn't really happen...
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2013-04-05 19:04:58 +00:00
|
|
|
default:
|
2017-08-04 12:43:02 +00:00
|
|
|
color = cds.GetLayerColor( pad_layer );
|
2011-05-13 13:15:28 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
2013-04-05 19:04:58 +00:00
|
|
|
showActualMaskSize = pad_layer;
|
2011-05-13 13:15:28 +00:00
|
|
|
#endif
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-05 19:04:58 +00:00
|
|
|
// if SMD or connector pad and high contrast mode
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
if( ( aDraw_mode & GR_ALLOW_HIGHCONTRAST ) &&
|
2015-08-23 19:40:33 +00:00
|
|
|
( GetAttribute() == PAD_ATTRIB_SMD || GetAttribute() == PAD_ATTRIB_CONN ) &&
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts && displ_opts->m_ContrastModeDisplay )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
// when routing tracks
|
2015-02-28 20:50:35 +00:00
|
|
|
if( frame->GetToolId() == ID_TRACK_BUTT )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID routeTop = screen->m_Route_Layer_TOP;
|
|
|
|
PCB_LAYER_ID routeBot = screen->m_Route_Layer_BOTTOM;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
|
|
|
// if routing between copper and component layers,
|
|
|
|
// or the current layer is one of said 2 external copper layers,
|
|
|
|
// then highlight only the current layer.
|
2014-06-24 16:17:18 +00:00
|
|
|
if( ( screen->m_Active_Layer == F_Cu || screen->m_Active_Layer == B_Cu ) ||
|
|
|
|
( routeTop==F_Cu && routeBot==B_Cu ) ||
|
|
|
|
( routeTop==B_Cu && routeBot==F_Cu )
|
|
|
|
)
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
if( !IsOnLayer( screen->m_Active_Layer ) )
|
2017-02-20 16:57:41 +00:00
|
|
|
color = COLOR4D( DARKDARKGRAY );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
2009-11-12 15:43:38 +00:00
|
|
|
// else routing between an internal signal layer and some other
|
2015-08-23 19:40:33 +00:00
|
|
|
// layer. Grey out all PAD_ATTRIB_SMD pads not on current or the single
|
2009-11-12 15:43:38 +00:00
|
|
|
// selected external layer.
|
2008-12-14 19:45:05 +00:00
|
|
|
else if( !IsOnLayer( screen->m_Active_Layer )
|
|
|
|
&& !IsOnLayer( routeTop )
|
|
|
|
&& !IsOnLayer( routeBot ) )
|
|
|
|
{
|
2017-02-20 16:57:41 +00:00
|
|
|
color = COLOR4D( DARKDARKGRAY );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-23 19:40:33 +00:00
|
|
|
// when not edting tracks, show PAD_ATTRIB_SMD components not on active layer
|
2009-11-12 15:43:38 +00:00
|
|
|
// as greyed out
|
2008-12-14 19:45:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !IsOnLayer( screen->m_Active_Layer ) )
|
2017-02-20 16:57:41 +00:00
|
|
|
color = COLOR4D( DARKDARKGRAY );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-29 16:42:03 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
|
|
|
if( showActualMaskSize )
|
|
|
|
{
|
|
|
|
switch( showActualMaskSize )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Mask:
|
|
|
|
case F_Mask:
|
2010-03-29 16:42:03 +00:00
|
|
|
mask_margin.x = mask_margin.y = GetSolderMaskMargin();
|
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Paste:
|
|
|
|
case F_Paste:
|
2010-03-29 16:42:03 +00:00
|
|
|
mask_margin = GetSolderPasteMargin();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-04-05 19:04:58 +00:00
|
|
|
// Another layer which has no margin to handle
|
2010-03-29 16:42:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// if Contrast mode is ON and a technical layer active, show pads on this
|
|
|
|
// layer so we can see pads on paste or solder layer and the size of the
|
|
|
|
// mask
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
if( ( aDraw_mode & GR_ALLOW_HIGHCONTRAST ) &&
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts && displ_opts->m_ContrastModeDisplay && !IsCopperLayer( screen->m_Active_Layer ) )
|
2009-03-26 19:27:50 +00:00
|
|
|
{
|
|
|
|
if( IsOnLayer( screen->m_Active_Layer ) )
|
2009-10-21 19:16:25 +00:00
|
|
|
{
|
2017-08-04 12:43:02 +00:00
|
|
|
color = cds.GetLayerColor( screen->m_Active_Layer );
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2013-04-07 16:20:46 +00:00
|
|
|
// In high contrast mode, and if the active layer is the mask
|
2009-11-12 15:43:38 +00:00
|
|
|
// layer shows the pad size with the mask clearance
|
2009-10-21 19:16:25 +00:00
|
|
|
switch( screen->m_Active_Layer )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Mask:
|
|
|
|
case F_Mask:
|
2009-11-04 19:08:08 +00:00
|
|
|
mask_margin.x = mask_margin.y = GetSolderMaskMargin();
|
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case B_Paste:
|
|
|
|
case F_Paste:
|
2009-11-04 19:08:08 +00:00
|
|
|
mask_margin = GetSolderPasteMargin();
|
2009-10-21 19:16:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-03-26 19:27:50 +00:00
|
|
|
else
|
|
|
|
color = DARKDARKGRAY;
|
|
|
|
}
|
2018-02-17 18:05:16 +00:00
|
|
|
// If use asks for masks to be printed, then print them.
|
|
|
|
else if( screen->m_IsPrinting )
|
|
|
|
{
|
|
|
|
if( ( IsOnLayer( B_Paste ) && brd->IsLayerVisible( B_Paste ) ) ||
|
|
|
|
( IsOnLayer( F_Paste ) && brd->IsLayerVisible( F_Paste ) ) )
|
|
|
|
{
|
|
|
|
mask_margin = GetSolderPasteMargin();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( IsOnLayer( B_Mask ) && brd->IsLayerVisible( B_Mask ) ) ||
|
|
|
|
( IsOnLayer( F_Mask ) && brd->IsLayerVisible( F_Mask ) ) )
|
|
|
|
{
|
|
|
|
mask_margin.x = std::max( mask_margin.x, GetSolderMaskMargin() );
|
|
|
|
mask_margin.y = std::max( mask_margin.y, GetSolderMaskMargin() );
|
|
|
|
}
|
|
|
|
}
|
2009-03-26 19:27:50 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
if( ( aDraw_mode & GR_HIGHLIGHT ) && !( aDraw_mode & GR_AND ) )
|
|
|
|
color.SetToLegacyHighlightColor();
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
bool DisplayIsol = displ_opts && displ_opts->m_DisplayPadIsol;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( !( m_layerMask & LSET::AllCuMask() ).any() )
|
2011-09-07 19:41:04 +00:00
|
|
|
DisplayIsol = false;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
if( ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) &&
|
2017-11-29 08:48:41 +00:00
|
|
|
brd->IsElementVisible( LAYER_NON_PLATEDHOLES ) )
|
2013-04-07 16:20:46 +00:00
|
|
|
{
|
2011-08-19 13:08:24 +00:00
|
|
|
drawInfo.m_ShowNotPlatedHole = true;
|
2017-11-29 08:48:41 +00:00
|
|
|
drawInfo.m_NPHoleColor = cds.GetItemColor( LAYER_NON_PLATEDHOLES );
|
2013-04-07 16:20:46 +00:00
|
|
|
}
|
2018-02-04 09:46:38 +00:00
|
|
|
// Don't let pads that *should* be NPTHs get lost
|
|
|
|
else if ( PadShouldBeNPTH() )
|
|
|
|
{
|
|
|
|
drawInfo.m_ShowNotPlatedHole = true;
|
|
|
|
drawInfo.m_NPHoleColor = cds.GetItemColor( LAYER_MOD_TEXT_INVISIBLE );
|
|
|
|
}
|
2010-09-11 16:33:43 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
drawInfo.m_DrawMode = aDraw_mode;
|
|
|
|
drawInfo.m_Color = color;
|
2017-10-05 18:11:55 +00:00
|
|
|
drawInfo.m_NoNetMarkColor = cds.GetItemColor( LAYER_NO_CONNECTS );
|
2010-09-11 19:15:24 +00:00
|
|
|
drawInfo.m_DrawPanel = aPanel;
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_Mask_margin = mask_margin;
|
2017-03-13 03:19:33 +00:00
|
|
|
drawInfo.m_ShowNCMark = brd->IsElementVisible( LAYER_NO_CONNECTS );
|
2010-09-11 19:15:24 +00:00
|
|
|
drawInfo.m_IsPrinting = screen->m_IsPrinting;
|
2017-02-20 16:57:41 +00:00
|
|
|
color.a = 0.666;
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2009-09-19 16:15:40 +00:00
|
|
|
/* Get the pad clearance. This has a meaning only for Pcbnew.
|
2015-01-10 10:27:49 +00:00
|
|
|
* for CvPcb GetClearance() creates debug errors because
|
2009-11-12 15:43:38 +00:00
|
|
|
* there is no net classes so a call to GetClearance() is made only when
|
2015-01-10 10:27:49 +00:00
|
|
|
* needed (never needed in CvPcb)
|
2009-09-19 16:15:40 +00:00
|
|
|
*/
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_PadClearance = DisplayIsol ? GetClearance() : 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-04-07 16:20:46 +00:00
|
|
|
// Draw the pad number
|
2015-01-10 10:27:49 +00:00
|
|
|
if( displ_opts && !displ_opts->m_DisplayPadNum )
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_Display_padnum = false;
|
2009-09-10 15:22:26 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
if( displ_opts &&
|
|
|
|
(( displ_opts ->m_DisplayNetNamesMode == 0 ) || ( displ_opts->m_DisplayNetNamesMode == 2 )) )
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_Display_netname = false;
|
|
|
|
|
|
|
|
// Display net names is restricted to pads that are on the active layer
|
2013-04-04 21:35:01 +00:00
|
|
|
// in high contrast mode display
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
if( ( aDraw_mode & GR_ALLOW_HIGHCONTRAST ) &&
|
2015-01-10 10:27:49 +00:00
|
|
|
!IsOnLayer( screen->m_Active_Layer ) && displ_opts && displ_opts->m_ContrastModeDisplay )
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_Display_netname = false;
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
DrawShape( aPanel->GetClipBox(), aDC, drawInfo );
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
2016-04-06 18:15:49 +00:00
|
|
|
wxPoint coord[12];
|
2013-05-05 07:17:48 +00:00
|
|
|
double angle = m_Orient;
|
2010-09-20 16:21:47 +00:00
|
|
|
int seg_width;
|
2010-09-11 16:33:43 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawInfo.m_DrawMode );
|
2010-09-11 16:33:43 +00:00
|
|
|
|
|
|
|
// calculate pad shape position :
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
wxPoint shape_pos = ShapePos() - aDrawInfo.m_Offset;
|
2010-09-11 16:33:43 +00:00
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
wxSize halfsize = m_Size;
|
|
|
|
halfsize.x >>= 1;
|
|
|
|
halfsize.y >>= 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
switch( GetShape() )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_ShowPadFilled )
|
|
|
|
GRFilledCircle( aClipBox, aDC, shape_pos.x, shape_pos.y,
|
|
|
|
halfsize.x + aDrawInfo.m_Mask_margin.x, 0,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
else
|
2010-09-11 16:33:43 +00:00
|
|
|
GRCircle( aClipBox, aDC, shape_pos.x, shape_pos.y,
|
|
|
|
halfsize.x + aDrawInfo.m_Mask_margin.x,
|
|
|
|
m_PadSketchModePenSize, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_PadClearance )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
GRCircle( aClipBox,
|
|
|
|
aDC, shape_pos.x, shape_pos.y,
|
|
|
|
halfsize.x + aDrawInfo.m_PadClearance,
|
2013-06-27 19:12:01 +00:00
|
|
|
0, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
|
|
|
wxPoint segStart, segEnd;
|
2013-06-27 19:12:01 +00:00
|
|
|
seg_width = BuildSegmentFromOvalShape(segStart, segEnd, angle,
|
|
|
|
aDrawInfo.m_Mask_margin);
|
2010-09-20 16:21:47 +00:00
|
|
|
segStart += shape_pos;
|
|
|
|
segEnd += shape_pos;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_ShowPadFilled )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-20 16:21:47 +00:00
|
|
|
GRFillCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
|
|
|
|
seg_width, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-20 16:21:47 +00:00
|
|
|
GRCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
|
|
|
|
seg_width, m_PadSketchModePenSize, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 16:20:46 +00:00
|
|
|
// Draw the clearance line
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_PadClearance )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-20 16:21:47 +00:00
|
|
|
seg_width += 2 * aDrawInfo.m_PadClearance;
|
|
|
|
GRCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y,
|
|
|
|
seg_width, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
2010-09-11 16:33:43 +00:00
|
|
|
BuildPadPolygon( coord, aDrawInfo.m_Mask_margin, angle );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
coord[ii] += shape_pos;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
GRClosedPoly( aClipBox, aDC, 4, coord, aDrawInfo.m_ShowPadFilled,
|
|
|
|
aDrawInfo.m_ShowPadFilled ? 0 : m_PadSketchModePenSize,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_PadClearance )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2016-04-06 18:15:49 +00:00
|
|
|
#define SEGCOUNT 32 // number of segments to approximate a circle
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
TransformShapeWithClearanceToPolygon( outline, aDrawInfo.m_PadClearance, SEGCOUNT, 1.0 );
|
|
|
|
|
|
|
|
// Draw the polygon: Inflate creates only one convex polygon
|
2017-10-19 08:27:00 +00:00
|
|
|
if( outline.OutlineCount() > 0 )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
2016-04-06 18:15:49 +00:00
|
|
|
|
2017-10-19 08:27:00 +00:00
|
|
|
if( poly.PointCount() > 0 )
|
|
|
|
{
|
|
|
|
GRClosedPoly( aClipBox, aDC, poly.PointCount(),
|
|
|
|
(wxPoint*)&poly.Point( 0 ), false, 0,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
|
|
|
}
|
|
|
|
}
|
2016-04-06 18:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
{
|
|
|
|
// Use solder[Paste/Mask]size or pad size to build pad shape to draw
|
|
|
|
wxSize size( GetSize() );
|
|
|
|
size += aDrawInfo.m_Mask_margin * 2;
|
|
|
|
int corner_radius = GetRoundRectCornerRadius( size );
|
|
|
|
|
|
|
|
// Draw the polygon: Inflate creates only one convex polygon
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
bool filled = aDrawInfo.m_ShowPadFilled;
|
|
|
|
|
|
|
|
if( filled )
|
|
|
|
{
|
|
|
|
wxPoint centers[4];
|
|
|
|
GetRoundRectCornerCenters( centers, corner_radius, shape_pos,
|
|
|
|
size, GetOrientation() );
|
|
|
|
GRClosedPoly( aClipBox, aDC, 4, centers, true, corner_radius*2,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TransformRoundRectToPolygon( outline, shape_pos, size, GetOrientation(),
|
|
|
|
corner_radius, 64 );
|
|
|
|
|
2017-10-19 08:27:00 +00:00
|
|
|
if( outline.OutlineCount() > 0 )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
2016-04-06 18:15:49 +00:00
|
|
|
|
2017-10-19 08:27:00 +00:00
|
|
|
if( poly.PointCount() > 0 )
|
|
|
|
{
|
|
|
|
GRClosedPoly( aClipBox, aDC, poly.PointCount(),
|
|
|
|
(wxPoint*)&poly.Point( 0 ), aDrawInfo.m_ShowPadFilled, 0,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
|
|
|
}
|
|
|
|
}
|
2016-04-06 18:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aDrawInfo.m_PadClearance )
|
|
|
|
{
|
|
|
|
outline.RemoveAllContours();
|
|
|
|
size = GetSize();
|
|
|
|
size.x += aDrawInfo.m_PadClearance * 2;
|
|
|
|
size.y += aDrawInfo.m_PadClearance * 2;
|
|
|
|
corner_radius = GetRoundRectCornerRadius() + aDrawInfo.m_PadClearance;
|
|
|
|
|
|
|
|
TransformRoundRectToPolygon( outline, shape_pos, size, GetOrientation(),
|
|
|
|
corner_radius, 32 );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2017-10-19 08:27:00 +00:00
|
|
|
if( outline.OutlineCount() > 0 )
|
|
|
|
{
|
|
|
|
// Draw the polygon: Inflate creates only one convex polygon
|
|
|
|
SHAPE_LINE_CHAIN& clearance_poly = outline.Outline( 0 );
|
2016-04-06 18:15:49 +00:00
|
|
|
|
2017-10-19 08:27:00 +00:00
|
|
|
if( clearance_poly.PointCount() > 0 )
|
|
|
|
{
|
|
|
|
GRClosedPoly( aClipBox, aDC, clearance_poly.PointCount(),
|
|
|
|
(wxPoint*)&clearance_poly.Point( 0 ), false, 0,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
|
|
|
}
|
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
2016-04-06 18:15:49 +00:00
|
|
|
}
|
2010-09-11 16:33:43 +00:00
|
|
|
break;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
case PAD_SHAPE_CUSTOM:
|
|
|
|
{
|
|
|
|
// The full shape has 2 items
|
|
|
|
// 1- The anchor pad: a round or rect pad located at pad position
|
|
|
|
// 2- The custom complex shape
|
|
|
|
// Note: The anchor pad shape is containing by the custom complex shape polygon
|
|
|
|
// The anchor pad is shown to help user to see where is the anchor, only in sketch mode
|
|
|
|
// (In filled mode, it is merged with the basic shapes)
|
|
|
|
wxPoint pad_pos = GetPosition() - aDrawInfo.m_Offset;
|
|
|
|
|
|
|
|
// In sketch mode only: Draw the anchor pad: a round or rect pad
|
|
|
|
if( !aDrawInfo.m_ShowPadFilled )
|
|
|
|
{
|
|
|
|
if( GetAnchorPadShape() == PAD_SHAPE_RECT )
|
|
|
|
{
|
|
|
|
wxPoint poly[4];
|
|
|
|
poly[0] = wxPoint( - halfsize.x, - halfsize.y );
|
|
|
|
poly[1] = wxPoint( - halfsize.x, + halfsize.y );
|
|
|
|
poly[2] = wxPoint( + halfsize.x, + halfsize.y );
|
|
|
|
poly[3] = wxPoint( + halfsize.x, - halfsize.y );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ++ii )
|
|
|
|
{
|
|
|
|
RotatePoint( &poly[ii], m_Orient );
|
|
|
|
poly[ii] += pad_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRClosedPoly( aClipBox, aDC, 4, poly, false, 0,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GRCircle( aClipBox, aDC, pad_pos.x, pad_pos.y,
|
|
|
|
halfsize.x,
|
|
|
|
m_PadSketchModePenSize, aDrawInfo.m_Color );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SHAPE_POLY_SET outline; // Will contain the corners in board coordinates
|
|
|
|
outline.Append( m_customShapeAsPolygon );
|
2017-09-20 08:28:52 +00:00
|
|
|
CustomShapeAsPolygonToBoardPosition( &outline, pad_pos, GetOrientation() );
|
2017-01-13 17:51:22 +00:00
|
|
|
SHAPE_LINE_CHAIN* poly;
|
|
|
|
|
|
|
|
const int segmentToCircleCount = 32;
|
|
|
|
|
|
|
|
if( aDrawInfo.m_Mask_margin.x )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET clearance_outline;
|
|
|
|
clearance_outline.Append( outline );
|
|
|
|
clearance_outline.Inflate( aDrawInfo.m_Mask_margin.x, segmentToCircleCount );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Draw the polygon: only one polygon is expected
|
|
|
|
// However we provide a multi polygon shape drawing
|
|
|
|
// ( for the future or to show a non expected shape )
|
|
|
|
for( int jj = 0; jj < outline.OutlineCount(); ++jj )
|
|
|
|
{
|
|
|
|
poly = &outline.Outline( jj );
|
|
|
|
|
|
|
|
GRClosedPoly( aClipBox, aDC, poly->PointCount(),
|
|
|
|
(wxPoint*)&poly->Point( 0 ), aDrawInfo.m_ShowPadFilled, 0,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aDrawInfo.m_PadClearance )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET clearance_outline;
|
|
|
|
clearance_outline.Append( outline );
|
|
|
|
|
|
|
|
clearance_outline.Inflate( aDrawInfo.m_PadClearance, segmentToCircleCount );
|
|
|
|
|
|
|
|
for( int jj = 0; jj < clearance_outline.OutlineCount(); ++jj )
|
|
|
|
{
|
|
|
|
poly = &clearance_outline.Outline( jj );
|
|
|
|
|
2017-10-19 08:27:00 +00:00
|
|
|
if( poly->PointCount() > 0 )
|
|
|
|
{
|
|
|
|
GRClosedPoly( aClipBox, aDC, poly->PointCount(),
|
|
|
|
(wxPoint*)&poly->Point( 0 ), false, 0,
|
|
|
|
aDrawInfo.m_Color, aDrawInfo.m_Color );
|
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-07 16:20:46 +00:00
|
|
|
// Draw the pad hole
|
2011-11-24 17:32:51 +00:00
|
|
|
wxPoint holepos = m_Pos - aDrawInfo.m_Offset;
|
|
|
|
int hole = m_Drill.x >> 1;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
bool drawhole = hole > 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-04-07 16:20:46 +00:00
|
|
|
if( !aDrawInfo.m_ShowPadFilled && !aDrawInfo.m_ShowNotPlatedHole )
|
2011-08-19 13:08:24 +00:00
|
|
|
drawhole = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
if( drawhole )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
bool blackpenstate = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_IsPrinting )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
blackpenstate = GetGRForceBlackPenState();
|
|
|
|
GRForceBlackPen( false );
|
2014-06-20 11:13:04 +00:00
|
|
|
aDrawInfo.m_HoleColor = WHITE;
|
2015-12-20 14:09:06 +00:00
|
|
|
aDrawInfo.m_NPHoleColor = WHITE;
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-25 09:55:00 +00:00
|
|
|
{
|
|
|
|
GRSetDrawMode( aDC, ( aDrawInfo.m_DrawMode != GR_XOR ) ? GR_COPY : GR_XOR );
|
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D hole_color = aDrawInfo.m_HoleColor;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
if( aDrawInfo. m_ShowNotPlatedHole ) // Draw a specific hole color
|
|
|
|
hole_color = aDrawInfo.m_NPHoleColor;
|
|
|
|
|
2014-01-26 14:20:58 +00:00
|
|
|
switch( GetDrillShape() )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_DRILL_SHAPE_CIRCLE:
|
2017-05-04 06:54:30 +00:00
|
|
|
if( aDC->LogicalToDeviceXRel( hole ) > 1 ) // hole is drawn if hole > 1pixel
|
2010-09-11 16:33:43 +00:00
|
|
|
GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
|
2013-10-20 15:39:15 +00:00
|
|
|
hole_color, hole_color );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_DRILL_SHAPE_OBLONG:
|
2014-05-17 19:29:15 +00:00
|
|
|
{
|
|
|
|
wxPoint drl_start, drl_end;
|
|
|
|
GetOblongDrillGeometry( drl_start, drl_end, seg_width );
|
|
|
|
GRFilledSegment( aClipBox, aDC, holepos + drl_start,
|
|
|
|
holepos + drl_end, seg_width, hole_color );
|
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_IsPrinting )
|
2008-12-14 19:45:05 +00:00
|
|
|
GRForceBlackPen( blackpenstate );
|
|
|
|
}
|
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawInfo.m_DrawMode );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2013-04-07 16:20:46 +00:00
|
|
|
// Draw "No connect" ( / or \ or cross X ) if necessary
|
2014-02-25 10:40:34 +00:00
|
|
|
if( GetNetCode() == 0 && aDrawInfo.m_ShowNCMark )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2012-09-22 11:19:37 +00:00
|
|
|
int dx0 = std::min( halfsize.x, halfsize.y );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( m_layerMask[F_Cu] ) /* Draw \ */
|
2010-09-11 16:33:43 +00:00
|
|
|
GRLine( aClipBox, aDC, holepos.x - dx0, holepos.y - dx0,
|
2017-10-05 18:11:55 +00:00
|
|
|
holepos.x + dx0, holepos.y + dx0, 0, aDrawInfo.m_NoNetMarkColor );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( m_layerMask[B_Cu] ) // Draw /
|
2010-09-11 16:33:43 +00:00
|
|
|
GRLine( aClipBox, aDC, holepos.x + dx0, holepos.y - dx0,
|
2017-10-05 18:11:55 +00:00
|
|
|
holepos.x - dx0, holepos.y + dx0, 0, aDrawInfo.m_NoNetMarkColor );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 09:55:00 +00:00
|
|
|
if( !aDrawInfo.m_IsPrinting )
|
|
|
|
GRSetDrawMode( aDC, ( aDrawInfo.m_DrawMode != GR_XOR ) ? GR_COPY : GR_XOR );
|
2013-04-09 17:16:53 +00:00
|
|
|
|
2013-04-07 16:20:46 +00:00
|
|
|
// Draw the pad number
|
2010-09-11 16:33:43 +00:00
|
|
|
if( !aDrawInfo.m_Display_padnum && !aDrawInfo.m_Display_netname )
|
2008-12-14 19:45:05 +00:00
|
|
|
return;
|
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
wxPoint tpos0 = shape_pos; // Position of the centre of text
|
2008-12-14 19:45:05 +00:00
|
|
|
wxPoint tpos = tpos0;
|
2011-10-17 20:01:27 +00:00
|
|
|
wxSize AreaSize; // size of text area, normalized to AreaSize.y < AreaSize.x
|
2014-04-24 18:54:49 +00:00
|
|
|
int shortname_len = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-04-24 18:54:49 +00:00
|
|
|
if( aDrawInfo.m_Display_netname )
|
|
|
|
shortname_len = GetShortNetname().Len();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
if( GetShape() == PAD_SHAPE_CIRCLE )
|
2008-12-14 19:45:05 +00:00
|
|
|
angle = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
AreaSize = m_Size;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
if( m_Size.y > m_Size.x )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
angle += 900;
|
2011-11-24 17:32:51 +00:00
|
|
|
AreaSize.x = m_Size.y;
|
|
|
|
AreaSize.y = m_Size.x;
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( shortname_len > 0 ) // if there is a netname, provides room to display this netname
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
AreaSize.y /= 2; // Text used only the upper area of the
|
|
|
|
// pad. The lower area displays the net name
|
2010-09-11 16:33:43 +00:00
|
|
|
tpos.y -= AreaSize.y / 2;
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Calculate the position of text, that is the middle point of the upper
|
|
|
|
// area of the pad
|
2010-09-11 16:33:43 +00:00
|
|
|
RotatePoint( &tpos, shape_pos, angle );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2013-05-01 17:32:36 +00:00
|
|
|
// Draw text with an angle between -90 deg and + 90 deg
|
2013-05-05 07:17:48 +00:00
|
|
|
double t_angle = angle;
|
2008-12-14 19:45:05 +00:00
|
|
|
NORMALIZE_ANGLE_90( t_angle );
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Note: in next calculations, texte size is calculated for 3 or more
|
|
|
|
* chars. Of course, pads numbers and nets names can have less than 3
|
|
|
|
* chars. but after some tries, i found this is gives the best look
|
2009-03-26 19:27:50 +00:00
|
|
|
*/
|
2017-08-10 15:00:28 +00:00
|
|
|
constexpr int MIN_CHAR_COUNT = 3;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2017-08-10 15:00:28 +00:00
|
|
|
unsigned int tsize;
|
2013-06-29 09:52:22 +00:00
|
|
|
EDA_RECT* clipBox = aDrawInfo.m_DrawPanel?
|
|
|
|
aDrawInfo.m_DrawPanel->GetClipBox() : NULL;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_Display_padnum )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2017-08-10 15:00:28 +00:00
|
|
|
int numpad_len = std::max( (int) m_name.Length(), MIN_CHAR_COUNT );
|
|
|
|
tsize = std::min( (int) AreaSize.y, AreaSize.x / numpad_len );
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2013-04-09 17:16:53 +00:00
|
|
|
if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable when size too small.
|
2009-03-26 19:27:50 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
// tsize reserve room for marges and segments thickness
|
2013-04-10 19:09:59 +00:00
|
|
|
tsize = ( tsize * 7 ) / 10;
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicHaloText( clipBox, aDC, tpos,
|
2013-05-01 19:01:14 +00:00
|
|
|
aDrawInfo.m_Color, BLACK, WHITE,
|
2017-08-10 15:00:28 +00:00
|
|
|
m_name, t_angle,
|
2013-04-09 17:16:53 +00:00
|
|
|
wxSize( tsize , tsize ), GR_TEXT_HJUSTIFY_CENTER,
|
|
|
|
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
|
|
|
|
|
2009-03-26 19:27:50 +00:00
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 19:27:50 +00:00
|
|
|
// display the short netname, if exists
|
|
|
|
if( shortname_len == 0 )
|
2008-12-14 19:45:05 +00:00
|
|
|
return;
|
2009-03-26 19:27:50 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
shortname_len = std::max( shortname_len, MIN_CHAR_COUNT );
|
2012-08-03 15:43:15 +00:00
|
|
|
tsize = std::min( AreaSize.y, AreaSize.x / shortname_len );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2013-04-09 17:16:53 +00:00
|
|
|
if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable in size too small.
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
tpos = tpos0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_Display_padnum )
|
|
|
|
tpos.y += AreaSize.y / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
RotatePoint( &tpos, shape_pos, angle );
|
|
|
|
|
|
|
|
// tsize reserve room for marges and segments thickness
|
2013-04-10 19:09:59 +00:00
|
|
|
tsize = ( tsize * 7 ) / 10;
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicHaloText( clipBox, aDC, tpos,
|
2013-05-01 19:01:14 +00:00
|
|
|
aDrawInfo.m_Color, BLACK, WHITE,
|
Removed D_PAD::SetNetname() function and D_PAD::m_Netname, D_PAD::m_ShortNetname fields.
D_PAD::GetNetname() and D_PAD::GetShortNetname() were moved to BOARD_CONNECTED_ITEM. Now they use the net name stored in NETINFO_ITEM.
Moved some one-line functions from class_board_connected_item.cpp to class_board_connected_item.h.
Added a copyright notice, moved Doxygen comments from class_board_connected_item.cpp to class_board_connected_item.h.
I have some doubts if changes introduced pcbnew/dialogs/dialog_pad_properties.cpp do not break anything, but I could not find a test case that breaks the pcbnew.
Performed tests:
- changed pad's net name from empty to existent - ok, name was changed
- changed pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty
- changed pad's net name from existent to empty - ok, net name became empty
- changed pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed
- (re)reading netlists, including net changes - fine, changes are applied, but empty nets are still kept
- loaded pcbnew/pcad2kicadpcb_plugin/examples/CK1202_V1.pcb to test P-CAD import plugin - ok, net names are correct
- imported an Eagle 6.0 board (Arduino Uno; http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip) then saved in .kicad_pcb format and reloaded - ok, net names are correct
- saved demos/video/video.kicad_pcb in legacy format and then loaded it again - ok, net names are correct
2014-01-14 09:41:52 +00:00
|
|
|
GetShortNetname(), t_angle,
|
2013-04-09 17:16:53 +00:00
|
|
|
wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
|
|
|
|
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function BuildSegmentFromOvalShape
|
2010-09-20 16:21:47 +00:00
|
|
|
* Has meaning only for OVAL (and ROUND) pads.
|
|
|
|
* Build an equivalent segment having the same shape as the OVAL shape,
|
|
|
|
* aSegStart and aSegEnd are the ending points of the equivalent segment of the shape
|
|
|
|
* aRotation is the asked rotation of the segment (usually m_Orient)
|
|
|
|
*/
|
2013-05-01 17:32:36 +00:00
|
|
|
int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd,
|
2013-06-27 19:12:01 +00:00
|
|
|
double aRotation, const wxSize& aMargin) const
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
|
|
|
int width;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
if( m_Size.y < m_Size.x ) // Build an horizontal equiv segment
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
2011-11-24 17:32:51 +00:00
|
|
|
int delta = ( m_Size.x - m_Size.y ) / 2;
|
2013-06-27 19:12:01 +00:00
|
|
|
aSegStart.x = -delta - aMargin.x;
|
2010-09-20 16:21:47 +00:00
|
|
|
aSegStart.y = 0;
|
2013-06-27 19:12:01 +00:00
|
|
|
aSegEnd.x = delta + aMargin.x;
|
2010-09-20 16:21:47 +00:00
|
|
|
aSegEnd.y = 0;
|
2013-06-27 19:12:01 +00:00
|
|
|
width = m_Size.y + ( aMargin.y * 2 );
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
else // Vertical oval: build a vertical equiv segment
|
|
|
|
{
|
2011-11-24 17:32:51 +00:00
|
|
|
int delta = ( m_Size.y -m_Size.x ) / 2;
|
2010-09-20 16:21:47 +00:00
|
|
|
aSegStart.x = 0;
|
2013-06-27 19:12:01 +00:00
|
|
|
aSegStart.y = -delta - aMargin.y;
|
2010-09-20 16:21:47 +00:00
|
|
|
aSegEnd.x = 0;
|
2013-06-27 19:12:01 +00:00
|
|
|
aSegEnd.y = delta + aMargin.y;
|
|
|
|
width = m_Size.x + ( aMargin.x * 2 );
|
2010-09-20 16:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aRotation )
|
|
|
|
{
|
|
|
|
RotatePoint( &aSegStart, aRotation);
|
|
|
|
RotatePoint( &aSegEnd, aRotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
return width;
|
|
|
|
}
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-05-01 17:32:36 +00:00
|
|
|
void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aRotation ) const
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
|
|
|
wxSize delta;
|
|
|
|
wxSize halfsize;
|
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
halfsize.x = m_Size.x >> 1;
|
|
|
|
halfsize.y = m_Size.y >> 1;
|
2010-09-11 16:33:43 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
switch( GetShape() )
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_RECT:
|
2013-05-01 19:01:14 +00:00
|
|
|
// For rectangular shapes, inflate is easy
|
|
|
|
halfsize += aInflateValue;
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
// Verify if do not deflate more than than size
|
|
|
|
// Only possible for inflate negative values.
|
|
|
|
if( halfsize.x < 0 )
|
|
|
|
halfsize.x = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
if( halfsize.y < 0 )
|
|
|
|
halfsize.y = 0;
|
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
2013-05-01 19:01:14 +00:00
|
|
|
// Trapezoidal pad: verify delta values
|
|
|
|
delta.x = ( m_DeltaSize.x >> 1 );
|
|
|
|
delta.y = ( m_DeltaSize.y >> 1 );
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
// be sure delta values are not to large
|
|
|
|
if( (delta.x < 0) && (delta.x <= -halfsize.y) )
|
|
|
|
delta.x = -halfsize.y + 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
if( (delta.x > 0) && (delta.x >= halfsize.y) )
|
|
|
|
delta.x = halfsize.y - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
if( (delta.y < 0) && (delta.y <= -halfsize.x) )
|
|
|
|
delta.y = -halfsize.x + 1;
|
|
|
|
|
|
|
|
if( (delta.y > 0) && (delta.y >= halfsize.x) )
|
|
|
|
delta.y = halfsize.x - 1;
|
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
default: // is used only for rect and trap. pads
|
|
|
|
return;
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build the basic rectangular or trapezoid shape
|
2010-09-11 19:15:24 +00:00
|
|
|
// delta is null for rectangular shapes
|
2010-09-11 16:33:43 +00:00
|
|
|
aCoord[0].x = -halfsize.x - delta.y; // lower left
|
|
|
|
aCoord[0].y = +halfsize.y + delta.x;
|
|
|
|
|
|
|
|
aCoord[1].x = -halfsize.x + delta.y; // upper left
|
|
|
|
aCoord[1].y = -halfsize.y - delta.x;
|
|
|
|
|
|
|
|
aCoord[2].x = +halfsize.x - delta.y; // upper right
|
|
|
|
aCoord[2].y = -halfsize.y + delta.x;
|
|
|
|
|
|
|
|
aCoord[3].x = +halfsize.x + delta.y; // lower right
|
|
|
|
aCoord[3].y = +halfsize.y - delta.x;
|
|
|
|
|
|
|
|
// Offsetting the trapezoid shape id needed
|
|
|
|
// It is assumed delta.x or/and delta.y == 0
|
2015-08-23 19:40:33 +00:00
|
|
|
if( GetShape() == PAD_SHAPE_TRAPEZOID && (aInflateValue.x != 0 || aInflateValue.y != 0) )
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
|
|
|
double angle;
|
|
|
|
wxSize corr;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( delta.y ) // lower and upper segment is horizontal
|
2009-09-19 16:15:40 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
// Calculate angle of left (or right) segment with vertical axis
|
2016-01-17 15:59:24 +00:00
|
|
|
angle = atan2( (double) m_DeltaSize.y, (double) m_Size.y );
|
2010-09-11 16:33:43 +00:00
|
|
|
|
|
|
|
// left and right sides are moved by aInflateValue.x in their perpendicular direction
|
|
|
|
// We must calculate the corresponding displacement on the horizontal axis
|
|
|
|
// that is delta.x +- corr.x depending on the corner
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
corr.x = KiROUND( tan( angle ) * aInflateValue.x );
|
|
|
|
delta.x = KiROUND( aInflateValue.x / cos( angle ) );
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
// Horizontal sides are moved up and down by aInflateValue.y
|
|
|
|
delta.y = aInflateValue.y;
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
// corr.y = 0 by the constructor
|
|
|
|
}
|
|
|
|
else if( delta.x ) // left and right segment is vertical
|
|
|
|
{
|
|
|
|
// Calculate angle of lower (or upper) segment with horizontal axis
|
2016-01-17 15:59:24 +00:00
|
|
|
angle = atan2( (double) m_DeltaSize.x, (double) m_Size.x );
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
// lower and upper sides are moved by aInflateValue.x in their perpendicular direction
|
|
|
|
// We must calculate the corresponding displacement on the vertical axis
|
|
|
|
// that is delta.y +- corr.y depending on the corner
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
corr.y = KiROUND( tan( angle ) * aInflateValue.y );
|
|
|
|
delta.y = KiROUND( aInflateValue.y / cos( angle ) );
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
// Vertical sides are moved left and right by aInflateValue.x
|
|
|
|
delta.x = aInflateValue.x;
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
// corr.x = 0 by the constructor
|
2010-09-11 19:15:24 +00:00
|
|
|
}
|
|
|
|
else // the trapezoid is a rectangle
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
2010-09-11 19:15:24 +00:00
|
|
|
delta = aInflateValue; // this pad is rectangular (delta null).
|
2009-09-19 16:15:40 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
aCoord[0].x += -delta.x - corr.x; // lower left
|
2010-09-11 16:33:43 +00:00
|
|
|
aCoord[0].y += delta.y + corr.y;
|
|
|
|
|
|
|
|
aCoord[1].x += -delta.x + corr.x; // upper left
|
|
|
|
aCoord[1].y += -delta.y - corr.y;
|
|
|
|
|
|
|
|
aCoord[2].x += delta.x - corr.x; // upper right
|
|
|
|
aCoord[2].y += -delta.y + corr.y;
|
|
|
|
|
|
|
|
aCoord[3].x += delta.x + corr.x; // lower right
|
|
|
|
aCoord[3].y += delta.y - corr.y;
|
2010-09-11 19:15:24 +00:00
|
|
|
|
|
|
|
/* test coordinates and clamp them if the offset correction is too large:
|
|
|
|
* Note: if a coordinate is bad, the other "symmetric" coordinate is bad
|
|
|
|
* So when a bad coordinate is found, the 2 symmetric coordinates
|
|
|
|
* are set to the minimun value (0)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( aCoord[0].x > 0 ) // lower left x coordinate must be <= 0
|
|
|
|
aCoord[0].x = aCoord[3].x = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
if( aCoord[1].x > 0 ) // upper left x coordinate must be <= 0
|
|
|
|
aCoord[1].x = aCoord[2].x = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
if( aCoord[0].y < 0 ) // lower left y coordinate must be >= 0
|
|
|
|
aCoord[0].y = aCoord[1].y = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
if( aCoord[3].y < 0 ) // lower right y coordinate must be >= 0
|
|
|
|
aCoord[3].y = aCoord[2].y = 0;
|
2010-09-11 16:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aRotation )
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
RotatePoint( &aCoord[ii], aRotation );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
}
|