2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-07-22 12:50:35 +00:00
|
|
|
* Copyright (C) 2018 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>
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2022-01-30 10:52:52 +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>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2012-04-27 14:15:11 +00:00
|
|
|
#include <base_units.h>
|
2020-07-15 16:23:36 +00:00
|
|
|
#include <geometry/shape_compound.h>
|
2021-07-14 20:03:32 +00:00
|
|
|
#include <pcb_shape.h>
|
2022-03-07 17:03:06 +00:00
|
|
|
#include <pcb_painter.h>
|
2022-01-30 10:52:52 +00:00
|
|
|
#include "macros.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
PCB_SHAPE::PCB_SHAPE( BOARD_ITEM* aParent, KICAD_T aItemType, SHAPE_T aShapeType ) :
|
|
|
|
BOARD_ITEM( aParent, aItemType ),
|
|
|
|
EDA_SHAPE( aShapeType, Millimeter2iu( DEFAULT_LINE_WIDTH ), FILL_T::NO_FILL, false )
|
2008-01-16 18:48:04 +00:00
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PCB_SHAPE::PCB_SHAPE( BOARD_ITEM* aParent, SHAPE_T shapetype ) :
|
|
|
|
BOARD_ITEM( aParent, PCB_SHAPE_T ),
|
2021-10-30 14:08:44 +00:00
|
|
|
EDA_SHAPE( shapetype, Millimeter2iu( DEFAULT_LINE_WIDTH ), FILL_T::NO_FILL, false )
|
2021-07-17 18:52:13 +00:00
|
|
|
{
|
2008-01-16 18:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE::~PCB_SHAPE()
|
2008-01-16 18:48:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I PCB_SHAPE::GetFocusPosition() const
|
2021-07-22 08:36:57 +00:00
|
|
|
{
|
|
|
|
// For some shapes return the visual center, but for not filled polygonal shapes,
|
|
|
|
// the center is usually far from the shape: a point on the outline is better
|
|
|
|
|
|
|
|
switch( m_shape )
|
|
|
|
{
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
if( !IsFilled() )
|
2022-01-01 18:57:44 +00:00
|
|
|
return VECTOR2I( GetCenter().x + GetRadius(), GetCenter().y );
|
2021-07-14 20:03:32 +00:00
|
|
|
else
|
|
|
|
return GetCenter();
|
2021-07-22 08:36:57 +00:00
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
if( !IsFilled() )
|
|
|
|
return GetStart();
|
2021-07-14 20:03:32 +00:00
|
|
|
else
|
|
|
|
return GetCenter();
|
2021-07-22 08:36:57 +00:00
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
if( !IsFilled() )
|
|
|
|
{
|
|
|
|
VECTOR2I pos = GetPolyShape().Outline(0).CPoint(0);
|
2022-01-01 18:57:44 +00:00
|
|
|
return VECTOR2I( pos.x, pos.y );
|
2021-07-22 08:36:57 +00:00
|
|
|
}
|
2021-07-14 20:03:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return GetCenter();
|
|
|
|
}
|
2021-07-22 08:36:57 +00:00
|
|
|
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
return GetArcMid();
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
return GetStart();
|
2020-08-21 18:55:52 +00:00
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
default:
|
2021-07-14 20:03:32 +00:00
|
|
|
return GetCenter();
|
2019-04-14 17:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
std::vector<VECTOR2I> PCB_SHAPE::GetCorners() const
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2I> pts;
|
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::RECT )
|
|
|
|
{
|
|
|
|
pts = GetRectCorners();
|
|
|
|
}
|
|
|
|
else if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
for( const VECTOR2I& pt : GetPolyShape().Outline( 0 ).CPoints() )
|
|
|
|
pts.emplace_back( pt );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
while( pts.size() < 4 )
|
|
|
|
pts.emplace_back( pts.back() + VECTOR2I( 10, 10 ) );
|
|
|
|
|
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PCB_SHAPE::Move( const VECTOR2I& aMoveVector )
|
2017-12-18 17:24:25 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
move( aMoveVector );
|
2017-12-18 17:24:25 +00:00
|
|
|
}
|
|
|
|
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
void PCB_SHAPE::Scale( double aScale )
|
2020-06-24 11:12:39 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
scale( aScale );
|
2020-06-24 11:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-13 19:32:00 +00:00
|
|
|
void PCB_SHAPE::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2022-01-16 21:15:20 +00:00
|
|
|
rotate( aRotCentre, aAngle );
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2011-08-08 23:50:55 +00:00
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PCB_SHAPE::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
flip( aCentre, aFlipLeftRight );
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2021-02-20 12:16:45 +00:00
|
|
|
SetLayer( FlipLayer( GetLayer(), GetBoard()->GetCopperLayerCount() ) );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 11:04:01 +00:00
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
FOOTPRINT* PCB_SHAPE::GetParentFootprint() const
|
2020-07-22 23:05:22 +00:00
|
|
|
{
|
2022-06-03 23:01:52 +00:00
|
|
|
return dynamic_cast<FOOTPRINT*>( BOARD_ITEM::GetParentFootprint() );
|
2018-07-07 11:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
EDA_ANGLE PCB_SHAPE::getParentOrientation() const
|
2015-02-12 03:22:24 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
if( GetParentFootprint() )
|
2022-01-16 21:15:20 +00:00
|
|
|
return GetParentFootprint()->GetOrientation();
|
2021-07-14 20:03:32 +00:00
|
|
|
else
|
2022-01-16 21:15:20 +00:00
|
|
|
return ANGLE_0;
|
2015-02-12 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I PCB_SHAPE::getParentPosition() const
|
2011-12-14 04:29:25 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
if( GetParentFootprint() )
|
|
|
|
return GetParentFootprint()->GetPosition();
|
|
|
|
else
|
2022-01-11 00:49:49 +00:00
|
|
|
return VECTOR2I( 0, 0 );
|
2011-12-14 04:29:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
|
2022-03-07 17:03:06 +00:00
|
|
|
double PCB_SHAPE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
|
|
|
|
{
|
|
|
|
constexpr double HIDE = std::numeric_limits<double>::max();
|
|
|
|
constexpr double SHOW = 0.0;
|
|
|
|
|
|
|
|
KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( aView->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
|
|
|
|
|
|
|
|
if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
|
|
|
|
{
|
|
|
|
// Hide shadow if the main layer is not shown
|
|
|
|
if( !aView->IsLayerVisible( m_layer ) )
|
|
|
|
return HIDE;
|
|
|
|
|
|
|
|
// Hide shadow on dimmed tracks
|
|
|
|
if( renderSettings->GetHighContrast() )
|
|
|
|
{
|
|
|
|
if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
|
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SHOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
void PCB_SHAPE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2018-12-08 15:26:47 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
aList.emplace_back( _( "Type" ), _( "Drawing" ) );
|
2019-04-14 17:58:35 +00:00
|
|
|
|
2021-10-31 16:32:24 +00:00
|
|
|
if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
|
2021-07-14 20:03:32 +00:00
|
|
|
aList.emplace_back( _( "Status" ), _( "Locked" ) );
|
2012-07-05 09:29:42 +00:00
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
ShapeGetMsgPanelInfo( aFrame, aList );
|
2012-07-05 09:29:42 +00:00
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
aList.emplace_back( _( "Layer" ), GetLayerName() );
|
2008-05-05 19:46:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
wxString PCB_SHAPE::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2020-08-09 23:03:31 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
return wxString::Format( _( "%s on %s" ), ShowShape(), GetLayerName() );
|
2020-08-09 23:03:31 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 18:55:40 +00:00
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
BITMAPS PCB_SHAPE::GetMenuImage() const
|
2021-06-02 04:50:46 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
return BITMAPS::add_dashed_line;
|
2021-06-02 04:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
EDA_ITEM* PCB_SHAPE::Clone() const
|
2021-01-19 23:07:31 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
return new PCB_SHAPE( *this );
|
2021-01-19 23:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
const BOX2I PCB_SHAPE::ViewBBox() const
|
2011-12-02 21:56:47 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
BOX2I return_box = EDA_ITEM::ViewBBox();
|
2021-10-26 12:18:08 +00:00
|
|
|
|
|
|
|
// Inflate the bounding box by just a bit more for safety.
|
|
|
|
return_box.Inflate( GetWidth() );
|
2011-08-08 23:50:55 +00:00
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
return return_box;
|
2011-08-08 23:50:55 +00:00
|
|
|
}
|
|
|
|
|
2008-05-05 19:46:54 +00:00
|
|
|
|
2022-03-16 23:48:24 +00:00
|
|
|
std::shared_ptr<SHAPE> PCB_SHAPE::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
|
2008-01-16 18:48:04 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
return std::make_shared<SHAPE_COMPOUND>( MakeEffectiveShapes() );
|
2008-01-16 18:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
void PCB_SHAPE::SwapData( BOARD_ITEM* aImage )
|
2008-01-16 18:48:04 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
PCB_SHAPE* image = dynamic_cast<PCB_SHAPE*>( aImage );
|
|
|
|
assert( image );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
SwapShape( image );
|
2019-10-31 15:25:39 +00:00
|
|
|
|
2020-11-14 14:29:11 +00:00
|
|
|
std::swap( m_layer, image->m_layer );
|
2021-10-27 20:56:32 +00:00
|
|
|
std::swap( m_fill, image->m_fill );
|
2020-11-14 18:11:28 +00:00
|
|
|
std::swap( m_flags, image->m_flags );
|
|
|
|
std::swap( m_status, image->m_status );
|
|
|
|
std::swap( m_parent, image->m_parent );
|
2020-08-02 10:54:25 +00:00
|
|
|
std::swap( m_forceVisible, image->m_forceVisible );
|
2017-10-31 13:59:03 +00:00
|
|
|
}
|
2020-02-02 18:40:14 +00:00
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
bool PCB_SHAPE::cmp_drawings::operator()( const BOARD_ITEM* aFirst,
|
|
|
|
const BOARD_ITEM* aSecond ) const
|
2020-07-24 22:08:36 +00:00
|
|
|
{
|
|
|
|
if( aFirst->Type() != aSecond->Type() )
|
|
|
|
return aFirst->Type() < aSecond->Type();
|
|
|
|
|
|
|
|
if( aFirst->GetLayer() != aSecond->GetLayer() )
|
|
|
|
return aFirst->GetLayer() < aSecond->GetLayer();
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( aFirst->Type() == PCB_SHAPE_T )
|
2020-07-24 22:08:36 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
const PCB_SHAPE* dwgA = static_cast<const PCB_SHAPE*>( aFirst );
|
|
|
|
const PCB_SHAPE* dwgB = static_cast<const PCB_SHAPE*>( aSecond );
|
2020-07-24 22:08:36 +00:00
|
|
|
|
|
|
|
if( dwgA->GetShape() != dwgB->GetShape() )
|
|
|
|
return dwgA->GetShape() < dwgB->GetShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aFirst->m_Uuid < aSecond->m_Uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-25 19:50:33 +00:00
|
|
|
void PCB_SHAPE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
PCB_LAYER_ID aLayer, int aClearanceValue,
|
|
|
|
int aError, ERROR_LOC aErrorLoc,
|
|
|
|
bool ignoreLineWidth ) const
|
|
|
|
{
|
|
|
|
EDA_SHAPE::TransformShapeWithClearanceToPolygon( aCornerBuffer, aClearanceValue, aError,
|
|
|
|
aErrorLoc, ignoreLineWidth );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-14 20:03:32 +00:00
|
|
|
static struct PCB_SHAPE_DESC
|
2020-02-02 18:40:14 +00:00
|
|
|
{
|
2021-07-14 20:03:32 +00:00
|
|
|
PCB_SHAPE_DESC()
|
2020-02-02 18:40:14 +00:00
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2020-10-04 23:34:59 +00:00
|
|
|
REGISTER_TYPE( PCB_SHAPE );
|
2021-07-14 20:03:32 +00:00
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_SHAPE, BOARD_ITEM> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_SHAPE, EDA_SHAPE> );
|
2020-10-04 23:34:59 +00:00
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( BOARD_ITEM ) );
|
2021-07-14 20:03:32 +00:00
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( EDA_SHAPE ) );
|
2020-02-02 18:40:14 +00:00
|
|
|
}
|
2021-07-14 20:03:32 +00:00
|
|
|
} _PCB_SHAPE_DESC;
|