2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 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_pad_draw_functions.cpp
|
|
|
|
*/
|
2008-12-14 19:45:05 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "trigo.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "class_pcb_screen.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "drawtxt.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "layers_id_colors_and_visibility.h"
|
|
|
|
#include "wxBasePcbFrame.h"
|
|
|
|
#include "pcbcommon.h"
|
|
|
|
#include "macros.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "pcbnew_id.h" // ID_TRACK_BUTT
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "pcbnew.h"
|
2010-01-29 20:36:12 +00:00
|
|
|
#include "colors_selection.h"
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "class_board.h"
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
m_DrawMode = 0;
|
|
|
|
m_Color = BLACK;
|
|
|
|
m_HoleColor = BLACK; // could be DARKGRAY;
|
2011-08-19 13:08:24 +00:00
|
|
|
m_NPHoleColor = YELLOW;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDraw_mode, const wxPoint& aOffset )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-11 19:15:24 +00:00
|
|
|
int color = 0;
|
|
|
|
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
|
2010-09-11 16:33:43 +00:00
|
|
|
* and this layer is a mask (solder mask or sloder paste
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
// Mask layers for Back side of board
|
|
|
|
#define BACK_SIDE_LAYERS \
|
2010-09-11 16:33:43 +00:00
|
|
|
(LAYER_BACK | ADHESIVE_LAYER_BACK | SOLDERPASTE_LAYER_BACK \
|
|
|
|
| SILKSCREEN_LAYER_BACK | SOLDERMASK_LAYER_BACK)
|
2010-01-26 18:02:03 +00:00
|
|
|
|
|
|
|
// Mask layers for Front side of board
|
|
|
|
#define FRONT_SIDE_LAYERS \
|
2010-09-11 16:33:43 +00:00
|
|
|
(LAYER_FRONT | ADHESIVE_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT \
|
|
|
|
| SILKSCREEN_LAYER_FRONT | SOLDERMASK_LAYER_FRONT)
|
2010-01-26 18:02:03 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
BOARD* brd = GetBoard();
|
|
|
|
bool frontVisible = brd->IsElementVisible( PCB_VISIBLE( PAD_FR_VISIBLE ) );
|
|
|
|
bool backVisible = brd->IsElementVisible( PCB_VISIBLE( PAD_BK_VISIBLE ) );
|
2010-01-26 18:02:03 +00:00
|
|
|
|
|
|
|
if( !frontVisible && !backVisible )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If pad are only on front side (no layer on back side)
|
|
|
|
* and if hide front side pads is enabled, do not draw
|
2010-09-11 16:33:43 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
if( !frontVisible && ( (m_layerMask & BACK_SIDE_LAYERS) == 0 ) )
|
2010-01-26 18:02:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If pad are only on back side (no layer on front side)
|
|
|
|
* and if hide back side pads is enabled, do not draw
|
2010-09-11 16:33:43 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
if( !backVisible && ( (m_layerMask & FRONT_SIDE_LAYERS) == 0 ) )
|
2010-01-26 18:02:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
|
|
|
|
PCB_SCREEN* screen = frame->GetScreen();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
if( frame->m_DisplayPadFill == FILLED )
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_ShowPadFilled = true;
|
|
|
|
else
|
|
|
|
drawInfo.m_ShowPadFilled = false;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( m_layerMask & LAYER_FRONT )
|
2010-01-26 18:02:03 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetVisibleElementColor( PAD_FR_VISIBLE );
|
2010-01-26 18:02:03 +00:00
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( m_layerMask & LAYER_BACK )
|
2010-01-26 18:02:03 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
color |= brd->GetVisibleElementColor( PAD_BK_VISIBLE );
|
2010-01-26 18:02:03 +00:00
|
|
|
}
|
2008-12-14 19:45:05 +00:00
|
|
|
|
|
|
|
if( color == 0 ) /* Not on copper layer */
|
|
|
|
{
|
2011-10-17 20:01:27 +00:00
|
|
|
// If the pad in on only one tech layer, use the layer color else use DARKGRAY
|
2011-09-07 19:41:04 +00:00
|
|
|
int mask_non_copper_layers = m_layerMask & ~ALL_CU_LAYERS;
|
2010-03-29 16:42:03 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
|
|
|
mask_non_copper_layers &= brd->GetVisibleLayers();
|
|
|
|
#endif
|
|
|
|
switch( mask_non_copper_layers )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-03-29 16:42:03 +00:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case ADHESIVE_LAYER_BACK:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( ADHESIVE_N_BACK );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case ADHESIVE_LAYER_FRONT:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( ADHESIVE_N_FRONT );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case SOLDERPASTE_LAYER_BACK:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( SOLDERPASTE_N_BACK );
|
2011-05-13 13:15:28 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
2010-03-29 16:42:03 +00:00
|
|
|
showActualMaskSize = SOLDERPASTE_N_BACK;
|
2011-05-13 13:15:28 +00:00
|
|
|
#endif
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case SOLDERPASTE_LAYER_FRONT:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( SOLDERPASTE_N_FRONT );
|
2011-05-13 13:15:28 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
2010-03-29 16:42:03 +00:00
|
|
|
showActualMaskSize = SOLDERPASTE_N_FRONT;
|
2011-05-13 13:15:28 +00:00
|
|
|
#endif
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case SILKSCREEN_LAYER_BACK:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( SILKSCREEN_N_BACK );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case SILKSCREEN_LAYER_FRONT:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( SILKSCREEN_N_FRONT );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case SOLDERMASK_LAYER_BACK:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( SOLDERMASK_N_BACK );
|
2011-05-13 13:15:28 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
2010-03-29 16:42:03 +00:00
|
|
|
showActualMaskSize = SOLDERMASK_N_BACK;
|
2011-05-13 13:15:28 +00:00
|
|
|
#endif
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 18:51:37 +00:00
|
|
|
case SOLDERMASK_LAYER_FRONT:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( SOLDERMASK_N_FRONT );
|
2011-05-13 13:15:28 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
2010-03-29 16:42:03 +00:00
|
|
|
showActualMaskSize = SOLDERMASK_N_FRONT;
|
2011-05-13 13:15:28 +00:00
|
|
|
#endif
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW_LAYER:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( DRAW_N );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMENT_LAYER:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( COMMENT_N );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ECO1_LAYER:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( ECO1_N );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ECO2_LAYER:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( ECO2_N );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDGE_LAYER:
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( EDGE_N );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
color = DARKGRAY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if PAD_SMD pad and high contrast mode
|
2011-09-07 19:41:04 +00:00
|
|
|
if( ( m_Attribut == PAD_SMD || m_Attribut == PAD_CONN ) && DisplayOpt.ContrastModeDisplay )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
// when routing tracks
|
2011-02-24 20:22:12 +00:00
|
|
|
if( frame && frame->GetToolId() == ID_TRACK_BUTT )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
int routeTop = screen->m_Route_Layer_TOP;
|
|
|
|
int routeBot = screen->m_Route_Layer_BOTTOM;
|
|
|
|
|
|
|
|
// 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.
|
2011-09-07 19:41:04 +00:00
|
|
|
if( ( ( 1 << routeTop ) | ( 1 << routeBot ) ) == ( LAYER_BACK | LAYER_FRONT )
|
|
|
|
|| ( ( 1 << screen->m_Active_Layer ) & ( LAYER_BACK | LAYER_FRONT ) ) )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
if( !IsOnLayer( screen->m_Active_Layer ) )
|
|
|
|
{
|
|
|
|
color &= ~MASKCOLOR;
|
|
|
|
color |= DARKDARKGRAY;
|
|
|
|
}
|
|
|
|
}
|
2009-11-12 15:43:38 +00:00
|
|
|
// else routing between an internal signal layer and some other
|
|
|
|
// layer. Grey out all PAD_SMD pads not on current or the single
|
|
|
|
// selected external layer.
|
2008-12-14 19:45:05 +00:00
|
|
|
else if( !IsOnLayer( screen->m_Active_Layer )
|
|
|
|
&& !IsOnLayer( routeTop )
|
|
|
|
&& !IsOnLayer( routeBot ) )
|
|
|
|
{
|
|
|
|
color &= ~MASKCOLOR;
|
|
|
|
color |= DARKDARKGRAY;
|
|
|
|
}
|
|
|
|
}
|
2009-11-12 15:43:38 +00:00
|
|
|
// when not edting tracks, show PAD_SMD components not on active layer
|
|
|
|
// as greyed out
|
2008-12-14 19:45:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !IsOnLayer( screen->m_Active_Layer ) )
|
|
|
|
{
|
|
|
|
color &= ~MASKCOLOR;
|
|
|
|
color |= DARKDARKGRAY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-29 16:42:03 +00:00
|
|
|
#ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR
|
|
|
|
if( showActualMaskSize )
|
|
|
|
{
|
|
|
|
switch( showActualMaskSize )
|
|
|
|
{
|
|
|
|
case SOLDERMASK_N_BACK:
|
|
|
|
case SOLDERMASK_N_FRONT:
|
|
|
|
mask_margin.x = mask_margin.y = GetSolderMaskMargin();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOLDERPASTE_N_BACK:
|
|
|
|
case SOLDERPASTE_N_FRONT:
|
|
|
|
mask_margin = GetSolderPasteMargin();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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
|
2010-03-29 16:42:03 +00:00
|
|
|
if( DisplayOpt.ContrastModeDisplay && screen->m_Active_Layer > LAST_COPPER_LAYER )
|
2009-03-26 19:27:50 +00:00
|
|
|
{
|
|
|
|
if( IsOnLayer( screen->m_Active_Layer ) )
|
2009-10-21 19:16:25 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
color = brd->GetLayerColor( screen->m_Active_Layer );
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// In hight contrast mode, and if the active layer is the mask
|
|
|
|
// layer shows the pad size with the mask clearance
|
2009-10-21 19:16:25 +00:00
|
|
|
switch( screen->m_Active_Layer )
|
|
|
|
{
|
2009-12-21 17:56:25 +00:00
|
|
|
case SOLDERMASK_N_BACK:
|
|
|
|
case SOLDERMASK_N_FRONT:
|
2009-11-04 19:08:08 +00:00
|
|
|
mask_margin.x = mask_margin.y = GetSolderMaskMargin();
|
|
|
|
break;
|
|
|
|
|
2009-12-21 17:56:25 +00:00
|
|
|
case SOLDERPASTE_N_BACK:
|
|
|
|
case SOLDERPASTE_N_FRONT:
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
if( aDraw_mode & GR_HIGHLIGHT )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDraw_mode & GR_AND )
|
2010-12-08 20:12:46 +00:00
|
|
|
color &= ~HIGHLIGHT_FLAG;
|
2008-12-14 19:45:05 +00:00
|
|
|
else
|
2010-12-08 20:12:46 +00:00
|
|
|
color |= HIGHLIGHT_FLAG;
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
if( color & HIGHLIGHT_FLAG )
|
2008-12-14 19:45:05 +00:00
|
|
|
color = ColorRefs[color & MASKCOLOR].m_LightColor;
|
|
|
|
|
|
|
|
bool DisplayIsol = DisplayOpt.DisplayPadIsol;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
if( ( m_layerMask & ALL_CU_LAYERS ) == 0 )
|
|
|
|
DisplayIsol = false;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
if( m_Attribut == PAD_HOLE_NOT_PLATED )
|
|
|
|
drawInfo.m_ShowNotPlatedHole = true;
|
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;
|
|
|
|
drawInfo.m_DrawPanel = aPanel;
|
2010-09-11 16:33:43 +00:00
|
|
|
drawInfo.m_Mask_margin = mask_margin;
|
2010-09-11 19:15:24 +00:00
|
|
|
drawInfo.m_ShowNCMark = brd->IsElementVisible( PCB_VISIBLE( NO_CONNECTS_VISIBLE ) );
|
|
|
|
drawInfo.m_IsPrinting = screen->m_IsPrinting;
|
2009-09-19 16:15:40 +00:00
|
|
|
SetAlpha( &color, 170 );
|
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.
|
2011-09-30 18:15:37 +00:00
|
|
|
* for CvPcb (and GerbView) 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
|
2011-09-30 18:15:37 +00:00
|
|
|
* needed (never needed in CvPcb nor in GerbView)
|
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
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
/* Draw the pad number */
|
|
|
|
if( frame && !frame->m_DisplayPadNum )
|
|
|
|
drawInfo.m_Display_padnum = false;
|
2009-09-10 15:22:26 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( ( DisplayOpt.DisplayNetNamesMode == 0 ) || ( DisplayOpt.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
|
2011-08-19 13:08:24 +00:00
|
|
|
// in hight contrast mode display
|
2010-09-11 16:33:43 +00:00
|
|
|
if( !IsOnLayer( screen->m_Active_Layer ) && DisplayOpt.ContrastModeDisplay )
|
|
|
|
drawInfo.m_Display_netname = false;
|
|
|
|
|
|
|
|
DrawShape( &aPanel->m_ClipBox, aDC, drawInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
wxPoint coord[4];
|
2010-09-20 16:21:47 +00:00
|
|
|
int delta_cx, delta_cy;
|
2010-09-11 19:15:24 +00:00
|
|
|
int 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 :
|
|
|
|
wxPoint shape_pos = ReturnShapePos() - aDrawInfo.m_Offset;
|
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
case PAD_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,
|
2009-03-26 19:27:50 +00:00
|
|
|
0,
|
2010-09-11 16:33:43 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
case PAD_OVAL:
|
2010-09-20 16:21:47 +00:00
|
|
|
{
|
|
|
|
wxPoint segStart, segEnd;
|
|
|
|
seg_width = BuildSegmentFromOvalShape(segStart, segEnd, angle);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Draw the isolation 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;
|
|
|
|
|
|
|
|
case PAD_RECT:
|
|
|
|
case PAD_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
|
|
|
{
|
2010-09-11 19:15:24 +00:00
|
|
|
BuildPadPolygon( coord, wxSize( aDrawInfo.m_PadClearance,
|
|
|
|
aDrawInfo.m_PadClearance ), angle );
|
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, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
2010-09-11 16:33:43 +00:00
|
|
|
break;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
if( !aDrawInfo.m_ShowPadFilled && !aDrawInfo. m_ShowNotPlatedHole )
|
|
|
|
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 );
|
2010-09-11 16:33:43 +00:00
|
|
|
aDrawInfo.m_HoleColor = g_DrawBgColor;
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( aDrawInfo.m_DrawMode != GR_XOR )
|
|
|
|
GRSetDrawMode( aDC, GR_COPY );
|
2008-12-14 19:45:05 +00:00
|
|
|
else
|
2010-09-11 16:33:43 +00:00
|
|
|
GRSetDrawMode( aDC, GR_XOR );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
int 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;
|
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
switch( m_DrillShape )
|
|
|
|
{
|
|
|
|
case PAD_CIRCLE:
|
2010-09-12 05:13:30 +00:00
|
|
|
if( aDC->LogicalToDeviceXRel( hole ) > 1 )
|
2010-09-11 16:33:43 +00:00
|
|
|
GRFilledCircle( aClipBox, aDC, holepos.x, holepos.y, hole, 0,
|
2011-08-19 13:08:24 +00:00
|
|
|
aDrawInfo.m_Color, hole_color );
|
2008-12-14 19:45:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_OVAL:
|
2011-11-24 17:32:51 +00:00
|
|
|
halfsize.x = m_Drill.x >> 1;
|
|
|
|
halfsize.y = m_Drill.y >> 1;
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
if( m_Drill.x > m_Drill.y ) /* horizontal */
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
delta_cx = halfsize.x - halfsize.y;
|
2009-11-12 15:43:38 +00:00
|
|
|
delta_cy = 0;
|
2011-11-24 17:32:51 +00:00
|
|
|
seg_width = m_Drill.y;
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
2009-11-12 15:43:38 +00:00
|
|
|
else /* vertical */
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
delta_cx = 0;
|
2010-09-11 16:33:43 +00:00
|
|
|
delta_cy = halfsize.y - halfsize.x;
|
2011-11-24 17:32:51 +00:00
|
|
|
seg_width = m_Drill.x;
|
2008-12-14 19:45:05 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
RotatePoint( &delta_cx, &delta_cy, angle );
|
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
GRFillCSegm( aClipBox, aDC, holepos.x + delta_cx, holepos.y + delta_cy,
|
2010-09-20 16:21:47 +00:00
|
|
|
holepos.x - delta_cx, holepos.y - delta_cy, seg_width,
|
2011-08-19 13:08:24 +00:00
|
|
|
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
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Draw "No connect" ( / or \ or cross X ) if necessary. : */
|
2010-09-11 16:33:43 +00:00
|
|
|
if( m_Netname.IsEmpty() && aDrawInfo.m_ShowNCMark )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2010-09-11 16:33:43 +00:00
|
|
|
int dx0 = MIN( halfsize.x, halfsize.y );
|
2008-12-14 19:45:05 +00:00
|
|
|
int nc_color = BLUE;
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( m_layerMask & LAYER_FRONT ) /* Draw \ */
|
2010-09-11 16:33:43 +00:00
|
|
|
GRLine( aClipBox, aDC, holepos.x - dx0, holepos.y - dx0,
|
|
|
|
holepos.x + dx0, holepos.y + dx0, 0, nc_color );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( m_layerMask & LAYER_BACK ) /* Draw / */
|
2010-09-11 16:33:43 +00:00
|
|
|
GRLine( aClipBox, aDC, holepos.x + dx0, holepos.y - dx0,
|
|
|
|
holepos.x - dx0, holepos.y + dx0, 0, nc_color );
|
2008-12-14 19:45:05 +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
|
2009-03-26 19:27:50 +00:00
|
|
|
int shortname_len = m_ShortNetname.Len();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( !aDrawInfo.m_Display_netname )
|
2009-03-26 19:27:50 +00:00
|
|
|
shortname_len = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
if( GetShape() == PAD_CIRCLE )
|
|
|
|
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
|
|
|
|
|
|
|
/* Draw text with an angle between -90 deg and + 90 deg */
|
|
|
|
int t_angle = angle;
|
|
|
|
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
|
|
|
*/
|
2008-12-14 19:45:05 +00:00
|
|
|
#define MIN_CHAR_COUNT 3
|
|
|
|
wxString buffer;
|
|
|
|
|
2009-09-19 16:15:40 +00:00
|
|
|
int tsize;
|
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
|
|
|
{
|
2009-03-26 19:27:50 +00:00
|
|
|
ReturnStringPadName( buffer );
|
|
|
|
int numpad_len = buffer.Len();
|
|
|
|
numpad_len = MAX( numpad_len, MIN_CHAR_COUNT );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2009-03-26 19:27:50 +00:00
|
|
|
tsize = min( AreaSize.y, AreaSize.x / numpad_len );
|
|
|
|
#define CHAR_SIZE_MIN 5
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
if( aDC->LogicalToDeviceXRel( tsize ) >= CHAR_SIZE_MIN ) // 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
|
|
|
|
tsize = (int) ( tsize * 0.8 );
|
|
|
|
DrawGraphicText( aDrawInfo.m_DrawPanel, aDC, tpos, WHITE, buffer, t_angle,
|
2009-11-12 15:43:38 +00:00
|
|
|
wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
|
2010-11-20 19:53:00 +00:00
|
|
|
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
|
|
|
|
|
|
|
shortname_len = MAX( shortname_len, MIN_CHAR_COUNT );
|
2008-12-15 10:24:19 +00:00
|
|
|
tsize = min( AreaSize.y, AreaSize.x / shortname_len );
|
2008-12-14 19:45:05 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
if( aDC->LogicalToDeviceXRel( tsize ) >= CHAR_SIZE_MIN ) // 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
|
|
|
|
tsize = (int) ( tsize * 0.8 );
|
|
|
|
DrawGraphicText( aDrawInfo.m_DrawPanel, aDC, tpos, WHITE, m_ShortNetname, t_angle,
|
|
|
|
wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER,
|
|
|
|
GR_TEXT_VJUSTIFY_CENTER, tsize / 7, false, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
*/
|
|
|
|
int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation) const
|
|
|
|
{
|
|
|
|
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;
|
2010-09-20 16:21:47 +00:00
|
|
|
aSegStart.x = -delta;
|
|
|
|
aSegStart.y = 0;
|
|
|
|
aSegEnd.x = delta;
|
|
|
|
aSegEnd.y = 0;
|
2011-11-24 17:32:51 +00:00
|
|
|
width = m_Size.y;
|
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;
|
|
|
|
aSegStart.y = -delta;
|
|
|
|
aSegEnd.x = 0;
|
|
|
|
aSegEnd.y = delta;
|
2011-11-24 17:32:51 +00:00
|
|
|
width = m_Size.x;
|
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
|
|
|
|
2010-09-20 16:21:47 +00:00
|
|
|
void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation ) const
|
2010-09-11 16:33:43 +00:00
|
|
|
{
|
|
|
|
if( (GetShape() != PAD_RECT) && (GetShape() != PAD_TRAPEZOID) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* For rectangular shapes, inflate is easy
|
|
|
|
*/
|
|
|
|
if( GetShape() == PAD_RECT )
|
|
|
|
{
|
|
|
|
halfsize += aInflateValue;
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2010-09-11 16:33:43 +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
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
if( halfsize.y < 0 )
|
|
|
|
halfsize.y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-11 19:15:24 +00:00
|
|
|
// Trapezoidal pad: verify delta values
|
2011-11-24 17:32:51 +00:00
|
|
|
delta.x = ( m_DeltaSize.x >> 1 );
|
|
|
|
delta.y = ( m_DeltaSize.y >> 1 );
|
2010-09-11 19:15:24 +00:00
|
|
|
|
2010-09-11 16:33:43 +00:00
|
|
|
// be sure delta values are not to large
|
2010-09-11 19:15:24 +00:00
|
|
|
if( (delta.x < 0) && (delta.x <= -halfsize.y) )
|
|
|
|
delta.x = -halfsize.y + 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
if( (delta.x > 0) && (delta.x >= halfsize.y) )
|
|
|
|
delta.x = halfsize.y - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
if( (delta.y < 0) && (delta.y <= -halfsize.x) )
|
|
|
|
delta.y = -halfsize.x + 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-09-11 19:15:24 +00:00
|
|
|
if( (delta.y > 0) && (delta.y >= halfsize.x) )
|
|
|
|
delta.y = halfsize.x - 1;
|
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
|
|
|
|
if( GetShape() == PAD_TRAPEZOID && (aInflateValue.x != 0 || aInflateValue.y != 0) )
|
|
|
|
{
|
|
|
|
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
|
2011-11-24 17:32:51 +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
|
2010-09-11 19:15:24 +00:00
|
|
|
corr.x = wxRound( tan( angle ) * aInflateValue.x );
|
|
|
|
delta.x = wxRound( aInflateValue.x / cos( angle ) );
|
|
|
|
|
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
|
2011-11-24 17:32:51 +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
|
2010-09-11 19:15:24 +00:00
|
|
|
corr.y = wxRound( tan( angle ) * aInflateValue.y );
|
|
|
|
delta.y = wxRound( aInflateValue.y / cos( angle ) );
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|