2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-12-31 14:46:40 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.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>
|
2022-01-29 17:19:22 +00:00
|
|
|
* Copyright (C) 1992-2022 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
|
|
|
|
*/
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <pcb_target.h>
|
2012-04-27 14:15:11 +00:00
|
|
|
#include <base_units.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/color_settings.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-10-16 15:51:24 +00:00
|
|
|
#include <i18n_utility.h>
|
2020-11-24 20:21:16 +00:00
|
|
|
#include <geometry/shape_circle.h>
|
2020-12-31 14:46:40 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2022-01-29 17:19:22 +00:00
|
|
|
#include <pcb_shape.h>
|
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
|
|
|
{
|
2020-11-24 20:21:16 +00:00
|
|
|
m_shape = 0;
|
2022-09-16 11:33:56 +00:00
|
|
|
m_size = pcbIUScale.mmToIU( 5 ); // Gives a decent size
|
|
|
|
m_lineWidth = pcbIUScale.mmToIU( DEFAULT_COPPER_LINE_WIDTH );
|
2020-11-24 20:21:16 +00:00
|
|
|
m_layer = Edge_Cuts; // a target is on all layers
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer, const VECTOR2I& aPos,
|
|
|
|
int aSize, int aWidth ) :
|
2011-12-01 06:04:23 +00:00
|
|
|
BOARD_ITEM( aParent, PCB_TARGET_T )
|
|
|
|
{
|
2020-11-24 20:21:16 +00:00
|
|
|
m_shape = aShape;
|
|
|
|
m_layer = aLayer;
|
|
|
|
m_pos = aPos;
|
|
|
|
m_size = aSize;
|
|
|
|
m_lineWidth = aWidth;
|
2011-12-01 06:04:23 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool PCB_TARGET::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2007-08-08 20:51:08 +00:00
|
|
|
{
|
2020-11-24 20:21:16 +00:00
|
|
|
int dX = aPosition.x - m_pos.x;
|
|
|
|
int dY = aPosition.y - m_pos.y;
|
|
|
|
int radius = aAccuracy + ( m_size / 2 );
|
2011-09-07 19:41:04 +00:00
|
|
|
return abs( dX ) <= radius && abs( dY ) <= radius;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool PCB_TARGET::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I arect = aRect;
|
2013-09-21 18:09:41 +00:00
|
|
|
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
|
|
|
|
2022-01-13 19:32:00 +00:00
|
|
|
void PCB_TARGET::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
RotatePoint( m_pos, aRotCentre, aAngle );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PCB_TARGET::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2019-07-12 21:02:10 +00:00
|
|
|
if( aFlipLeftRight )
|
2020-11-24 20:21:16 +00:00
|
|
|
m_pos.x = aCentre.x - ( m_pos.x - aCentre.x );
|
2019-07-12 21:02:10 +00:00
|
|
|
else
|
2020-11-24 20:21:16 +00:00
|
|
|
m_pos.y = aCentre.y - ( m_pos.y - aCentre.y );
|
2019-07-12 21:02:10 +00:00
|
|
|
|
2021-02-20 12:16:45 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2011-02-25 16:23:24 +00:00
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I PCB_TARGET::GetBoundingBox() const
|
2011-02-25 16:23:24 +00:00
|
|
|
{
|
2022-08-31 16:17:14 +00:00
|
|
|
BOX2I bBox;
|
2020-11-24 20:21:16 +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 );
|
2011-02-25 16:23:24 +00:00
|
|
|
|
|
|
|
return bBox;
|
|
|
|
}
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
|
2022-03-16 23:48:24 +00:00
|
|
|
std::shared_ptr<SHAPE> PCB_TARGET::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
|
2020-11-24 20:21:16 +00:00
|
|
|
{
|
|
|
|
return std::make_shared<SHAPE_CIRCLE>( m_pos, m_size / 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-19 16:09:59 +00:00
|
|
|
wxString PCB_TARGET::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
2013-04-07 11:55:18 +00:00
|
|
|
// Targets are on *every* layer by definition
|
2020-09-19 16:12:00 +00:00
|
|
|
return _( "Target" );
|
2011-07-14 15:42:44 +00:00
|
|
|
}
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS PCB_TARGET::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_pcb_target;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 23:23:58 +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
|
|
|
|
2019-05-28 23:23:58 +00:00
|
|
|
|
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) );
|
|
|
|
}
|
2019-05-28 23:23:58 +00:00
|
|
|
|
2020-02-02 18:40:14 +00:00
|
|
|
|
2020-12-31 14:46:40 +00:00
|
|
|
void PCB_TARGET::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
aList.emplace_back( _( "PCB Target" ), wxEmptyString );
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Layer" ), GetLayerName() );
|
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
aList.emplace_back( _( "Size" ), aFrame->MessageTextFromValue( GetSize() ) );
|
|
|
|
aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( GetWidth() ) );
|
2022-02-04 22:44:59 +00:00
|
|
|
aList.emplace_back( _( "Shape" ), GetShape() == 0 ? wxT( "+" ) : wxT( "X" ) );
|
2020-12-31 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-29 17:19:22 +00:00
|
|
|
void PCB_TARGET::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
2022-09-19 09:25:20 +00:00
|
|
|
PCB_LAYER_ID aLayer, int aClearanceValue,
|
|
|
|
int aError, ERROR_LOC aErrorLoc,
|
|
|
|
bool ignoreLineWidth ) const
|
2022-01-29 17:19:22 +00:00
|
|
|
{
|
|
|
|
int size = GetShape() ? GetSize() / 1.5 : GetSize() / 2.0;
|
|
|
|
int radius = GetShape() ? GetSize() / 2.0 : GetSize() / 3.0;
|
|
|
|
|
|
|
|
PCB_SHAPE line1, line2;
|
|
|
|
PCB_SHAPE circle( nullptr, SHAPE_T::CIRCLE );
|
|
|
|
line1.SetStart( VECTOR2I( -size, 0.0 ) );
|
2022-01-30 08:08:21 +00:00
|
|
|
line1.SetEnd( VECTOR2I( size, 0.0 ) );
|
2022-01-29 17:19:22 +00:00
|
|
|
line2.SetStart( VECTOR2I( 0.0, -size ) );
|
2022-01-30 08:08:21 +00:00
|
|
|
line2.SetEnd( VECTOR2I( 0.0, size ) );
|
2022-01-29 17:19:22 +00:00
|
|
|
circle.SetEndX( radius );
|
|
|
|
|
|
|
|
if( GetShape() ) // shape x
|
|
|
|
{
|
|
|
|
line1.Rotate( VECTOR2I(0,0), EDA_ANGLE( 45.0, DEGREES_T ) );
|
|
|
|
line2.Rotate( VECTOR2I(0,0), EDA_ANGLE( 45.0, DEGREES_T ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( PCB_SHAPE* item: { &line1, &line2, &circle } )
|
|
|
|
{
|
|
|
|
item->SetWidth( GetWidth() );
|
|
|
|
item->Move( GetPosition() );
|
|
|
|
item->TransformShapeWithClearanceToPolygon( aCornerBuffer, aLayer, aClearanceValue,
|
|
|
|
aError, aErrorLoc, ignoreLineWidth );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-02 18:40:14 +00:00
|
|
|
static struct PCB_TARGET_DESC
|
|
|
|
{
|
|
|
|
PCB_TARGET_DESC()
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( PCB_TARGET );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_TARGET ), TYPE_HASH( BOARD_ITEM ) );
|
2020-10-16 15:51:24 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TARGET, int>( _HKI( "Size" ),
|
2020-04-06 16:23:21 +00:00
|
|
|
&PCB_TARGET::SetSize, &PCB_TARGET::GetSize, PROPERTY_DISPLAY::PT_SIZE ) );
|
2020-10-16 15:51:24 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TARGET, int>( _HKI( "Width" ),
|
2020-04-06 16:23:21 +00:00
|
|
|
&PCB_TARGET::SetWidth, &PCB_TARGET::GetWidth, PROPERTY_DISPLAY::PT_SIZE ) );
|
2020-02-02 18:40:14 +00:00
|
|
|
|
2020-10-16 15:51:24 +00:00
|
|
|
auto shape = new PROPERTY<PCB_TARGET, int>( _HKI( "Shape" ),
|
2020-02-02 18:40:14 +00:00
|
|
|
&PCB_TARGET::SetShape, &PCB_TARGET::GetShape );
|
|
|
|
// TODO change the integer to an enum?
|
2020-10-16 15:51:24 +00:00
|
|
|
//shape->SetValues( { { 0, _HKI( "Cross" ) }, { 1, ( "Plus" ) } } );
|
2020-02-02 18:40:14 +00:00
|
|
|
propMgr.AddProperty( shape );
|
|
|
|
}
|
|
|
|
} _PCB_TARGET_DESC;
|