2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-01-14 19:50:32 +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
|
|
|
/**
|
2017-10-31 15:38:10 +00:00
|
|
|
* @file class_pcb_target.cpp
|
|
|
|
* PCB_TARGET class definition - targets for photo plots, formerly called MIRE (from French 'mire optique')
|
2011-09-23 13:57:12 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <richio.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
2017-10-31 15:38:10 +00:00
|
|
|
#include <class_pcb_target.h>
|
2012-04-27 14:15:11 +00:00
|
|
|
#include <base_units.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) :
|
|
|
|
BOARD_ITEM( aParent, PCB_TARGET_T )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-08 20:51:08 +00:00
|
|
|
m_Shape = 0;
|
2013-07-29 07:33:56 +00:00
|
|
|
m_Size = Millimeter2iu( 5 ); // Gives a decent size
|
|
|
|
m_Width = Millimeter2iu( 0.15 ); // Gives a decent width
|
2014-06-24 16:17:18 +00:00
|
|
|
m_Layer = Edge_Cuts; // a target is on all layers
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
|
2014-06-24 16:17:18 +00:00
|
|
|
const wxPoint& aPos, int aSize, int aWidth ) :
|
2011-12-01 06:04:23 +00:00
|
|
|
BOARD_ITEM( aParent, PCB_TARGET_T )
|
|
|
|
{
|
|
|
|
m_Shape = aShape;
|
|
|
|
m_Layer = aLayer;
|
|
|
|
m_Pos = aPos;
|
|
|
|
m_Size = aSize;
|
|
|
|
m_Width = aWidth;
|
|
|
|
}
|
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET::~PCB_TARGET()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
/* Draw PCB_TARGET object: 2 segments + 1 circle
|
2009-11-12 15:43:38 +00:00
|
|
|
* The circle radius is half the radius of the target
|
|
|
|
* 2 lines have length the diameter of the target
|
|
|
|
*/
|
2012-09-01 13:38:27 +00:00
|
|
|
void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color,
|
|
|
|
const wxPoint& offset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
int radius, ox, oy, width;
|
2007-08-08 20:51:08 +00:00
|
|
|
int dx1, dx2, dy1, dy2;
|
|
|
|
|
|
|
|
ox = m_Pos.x + offset.x;
|
|
|
|
oy = m_Pos.y + offset.y;
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
BOARD * brd = GetBoard( );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsLayerVisible( m_Layer ) == false )
|
2007-08-08 20:51:08 +00:00
|
|
|
return;
|
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
auto frame = static_cast<PCB_EDIT_FRAME*> ( panel->GetParent() );
|
|
|
|
auto gcolor = frame->Settings().Colors().GetLayerColor( m_Layer );
|
2009-10-10 01:25:53 +00:00
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
GRSetDrawMode( DC, mode_color );
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
|
2015-02-02 08:06:39 +00:00
|
|
|
bool filled = displ_opts ? displ_opts->m_DisplayDrawItemsFill : FILLED;
|
2007-08-08 20:51:08 +00:00
|
|
|
width = m_Width;
|
2010-02-08 18:15:42 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
radius = m_Size / 3;
|
2015-02-02 08:06:39 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( GetShape() ) // shape X
|
|
|
|
radius = m_Size / 2;
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2015-02-02 08:06:39 +00:00
|
|
|
if( filled )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCircle( panel->GetClipBox(), DC, ox, oy, radius, width, gcolor );
|
2015-02-02 08:06:39 +00:00
|
|
|
else
|
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCircle( panel->GetClipBox(), DC, ox, oy, radius + (width / 2), gcolor );
|
|
|
|
GRCircle( panel->GetClipBox(), DC, ox, oy, radius - (width / 2), gcolor );
|
2007-08-08 20:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
radius = m_Size / 2;
|
|
|
|
dx1 = radius;
|
2009-11-12 15:43:38 +00:00
|
|
|
dy1 = 0;
|
|
|
|
dx2 = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
dy2 = radius;
|
2007-08-08 20:51:08 +00:00
|
|
|
|
2012-09-20 18:58:41 +00:00
|
|
|
if( GetShape() ) // shape X
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2012-09-20 18:58:41 +00:00
|
|
|
dx1 = dy1 = radius;
|
2009-11-12 15:43:38 +00:00
|
|
|
dx2 = dx1;
|
|
|
|
dy2 = -dy1;
|
2007-08-08 20:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 08:06:39 +00:00
|
|
|
if( filled )
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor );
|
|
|
|
GRLine( panel->GetClipBox(), DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor );
|
2015-02-02 08:06:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor );
|
|
|
|
GRCSegm( panel->GetClipBox(), DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor );
|
2007-08-08 20:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
bool PCB_TARGET::HitTest( const wxPoint& aPosition ) const
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
int dX = aPosition.x - m_Pos.x;
|
|
|
|
int dY = aPosition.y - m_Pos.y;
|
2011-09-07 19:41:04 +00:00
|
|
|
int radius = m_Size / 2;
|
|
|
|
return abs( dX ) <= radius && abs( dY ) <= radius;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2013-09-21 18:09:41 +00:00
|
|
|
EDA_RECT arect = aRect;
|
|
|
|
arect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return arect.Contains( GetBoundingBox() );
|
|
|
|
else
|
|
|
|
return GetBoundingBox().Intersects( arect );
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void PCB_TARGET::Rotate(const wxPoint& aRotCentre, double aAngle)
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, aRotCentre, aAngle );
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_TARGET::Flip(const wxPoint& aCentre )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
|
2013-04-05 19:04:58 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer() ) );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2011-02-25 16:23:24 +00:00
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT PCB_TARGET::GetBoundingBox() const
|
2011-02-25 16:23:24 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bBox;
|
2011-02-25 16:23:24 +00:00
|
|
|
bBox.SetX( m_Pos.x - m_Size/2 );
|
|
|
|
bBox.SetY( m_Pos.y - m_Size/2 );
|
|
|
|
bBox.SetWidth( m_Size );
|
|
|
|
bBox.SetHeight( m_Size );
|
|
|
|
|
|
|
|
return bBox;
|
|
|
|
}
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString PCB_TARGET::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2013-04-07 11:55:18 +00:00
|
|
|
// Targets are on *every* layer by definition
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Target size %s" ), MessageTextFromValue( aUnits, m_Size ) );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF PCB_TARGET::GetMenuImage() const
|
|
|
|
{
|
2017-10-31 15:38:10 +00:00
|
|
|
return add_pcb_target_xpm;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* PCB_TARGET::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new PCB_TARGET( *this );
|
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
|
|
|
void PCB_TARGET::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_TARGET_T );
|
|
|
|
|
|
|
|
std::swap( *((PCB_TARGET*) this), *((PCB_TARGET*) aImage) );
|
|
|
|
}
|