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>
|
2023-01-18 07:34:52 +00:00
|
|
|
* Copyright (C) 1992-2023 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
|
|
|
|
*/
|
|
|
|
|
2024-01-20 23:35:29 +00:00
|
|
|
#include <google/protobuf/any.pb.h>
|
|
|
|
#include <magic_enum.hpp>
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2022-09-22 14:05:06 +00:00
|
|
|
#include <core/mirror.h>
|
|
|
|
#include <macros.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>
|
2023-09-04 18:44:39 +00:00
|
|
|
#include <pad.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>
|
2024-01-20 23:35:29 +00:00
|
|
|
#include <api/board/board_types.pb.h>
|
|
|
|
#include <api/api_enums.h>
|
|
|
|
#include <api/api_utils.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 ) :
|
2023-07-30 19:39:07 +00:00
|
|
|
BOARD_CONNECTED_ITEM( aParent, aItemType ),
|
2022-09-16 11:33:56 +00:00
|
|
|
EDA_SHAPE( aShapeType, pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), FILL_T::NO_FILL )
|
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 ) :
|
2023-07-30 19:39:07 +00:00
|
|
|
BOARD_CONNECTED_ITEM( aParent, PCB_SHAPE_T ),
|
2022-09-16 11:33:56 +00:00
|
|
|
EDA_SHAPE( shapetype, pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ), FILL_T::NO_FILL )
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-01-20 23:35:29 +00:00
|
|
|
|
|
|
|
void PCB_SHAPE::Serialize( google::protobuf::Any &aContainer ) const
|
|
|
|
{
|
|
|
|
kiapi::board::types::GraphicShape msg;
|
|
|
|
|
|
|
|
msg.mutable_id()->set_value( m_Uuid.AsStdString() );
|
|
|
|
msg.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
|
|
|
|
msg.set_locked( IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
|
|
|
|
: kiapi::common::types::LockedState::LS_UNLOCKED );
|
|
|
|
msg.mutable_net()->mutable_code()->set_value( GetNetCode() );
|
|
|
|
msg.mutable_net()->set_name( GetNetname() );
|
|
|
|
|
|
|
|
kiapi::common::types::StrokeAttributes* stroke
|
|
|
|
= msg.mutable_attributes()->mutable_stroke();
|
|
|
|
kiapi::common::types::GraphicFillAttributes* fill = msg.mutable_attributes()->mutable_fill();
|
|
|
|
|
|
|
|
stroke->mutable_width()->set_value_nm( GetWidth() );
|
|
|
|
|
|
|
|
switch( GetLineStyle() )
|
|
|
|
{
|
|
|
|
case LINE_STYLE::DEFAULT: stroke->set_style( kiapi::common::types::SLS_DEFAULT ); break;
|
|
|
|
case LINE_STYLE::SOLID: stroke->set_style( kiapi::common::types::SLS_SOLID ); break;
|
|
|
|
case LINE_STYLE::DASH: stroke->set_style( kiapi::common::types::SLS_DASH ); break;
|
|
|
|
case LINE_STYLE::DOT: stroke->set_style( kiapi::common::types::SLS_DOT ); break;
|
|
|
|
case LINE_STYLE::DASHDOT: stroke->set_style( kiapi::common::types::SLS_DASHDOT ); break;
|
|
|
|
case LINE_STYLE::DASHDOTDOT: stroke->set_style( kiapi::common::types::SLS_DASHDOTDOT ); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( GetFillMode() )
|
|
|
|
{
|
|
|
|
case FILL_T::FILLED_SHAPE: fill->set_fill_type( kiapi::common::types::GFT_FILLED ); break;
|
|
|
|
default: fill->set_fill_type( kiapi::common::types::GFT_UNFILLED ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::SEGMENT:
|
|
|
|
{
|
|
|
|
kiapi::board::types::GraphicSegmentAttributes* segment = msg.mutable_segment();
|
|
|
|
kiapi::common::PackVector2( *segment->mutable_start(), GetStart() );
|
|
|
|
kiapi::common::PackVector2( *segment->mutable_end(), GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::RECTANGLE:
|
|
|
|
{
|
|
|
|
kiapi::board::types::GraphicRectangleAttributes* rectangle = msg.mutable_rectangle();
|
|
|
|
kiapi::common::PackVector2( *rectangle->mutable_top_left(), GetStart() );
|
|
|
|
kiapi::common::PackVector2( *rectangle->mutable_bottom_right(), GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
{
|
|
|
|
kiapi::board::types::GraphicArcAttributes* arc = msg.mutable_arc();
|
|
|
|
kiapi::common::PackVector2( *arc->mutable_start(), GetStart() );
|
|
|
|
kiapi::common::PackVector2( *arc->mutable_mid(), GetArcMid() );
|
|
|
|
kiapi::common::PackVector2( *arc->mutable_end(), GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
{
|
|
|
|
kiapi::board::types::GraphicCircleAttributes* circle = msg.mutable_circle();
|
|
|
|
kiapi::common::PackVector2( *circle->mutable_center(), GetStart() );
|
|
|
|
kiapi::common::PackVector2( *circle->mutable_radius_point(), GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
{
|
|
|
|
kiapi::common::types::PolySet* polyset = msg.mutable_polygon();
|
|
|
|
|
|
|
|
for( int idx = 0; idx < GetPolyShape().OutlineCount(); ++idx )
|
|
|
|
{
|
|
|
|
const SHAPE_POLY_SET::POLYGON& poly = GetPolyShape().Polygon( idx );
|
|
|
|
|
|
|
|
if( poly.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
kiapi::common::types::PolygonWithHoles* polyMsg = polyset->mutable_polygons()->Add();
|
2024-04-04 22:55:58 +00:00
|
|
|
kiapi::common::PackPolyLine( *polyMsg->mutable_outline(), poly.front() );
|
2024-01-20 23:35:29 +00:00
|
|
|
|
|
|
|
if( poly.size() > 1 )
|
|
|
|
{
|
|
|
|
for( size_t hole = 1; hole < poly.size(); ++hole )
|
2024-04-04 22:55:58 +00:00
|
|
|
{
|
|
|
|
kiapi::common::types::PolyLine* pl = polyMsg->mutable_holes()->Add();
|
|
|
|
kiapi::common::PackPolyLine( *pl, poly[hole] );
|
|
|
|
}
|
2024-01-20 23:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
{
|
|
|
|
kiapi::board::types::GraphicBezierAttributes* bezier = msg.mutable_bezier();
|
|
|
|
kiapi::common::PackVector2( *bezier->mutable_start(), GetStart() );
|
|
|
|
kiapi::common::PackVector2( *bezier->mutable_control1(), GetBezierC1() );
|
|
|
|
kiapi::common::PackVector2( *bezier->mutable_control2(), GetBezierC2() );
|
|
|
|
kiapi::common::PackVector2( *bezier->mutable_end(), GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, "Unhandled shape in PCB_SHAPE::Serialize" );
|
|
|
|
}
|
|
|
|
|
|
|
|
aContainer.PackFrom( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_SHAPE::Deserialize( const google::protobuf::Any &aContainer )
|
|
|
|
{
|
|
|
|
kiapi::board::types::GraphicShape msg;
|
|
|
|
|
|
|
|
if( !aContainer.UnpackTo( &msg ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Initialize everything to a known state that doesn't get touched by every
|
|
|
|
// codepath below, to make sure the equality operator is consistent
|
|
|
|
m_start = {};
|
|
|
|
m_end = {};
|
|
|
|
m_arcCenter = {};
|
|
|
|
m_arcMidData = {};
|
|
|
|
m_bezierC1 = {};
|
|
|
|
m_bezierC2 = {};
|
|
|
|
m_editState = 0;
|
|
|
|
m_proxyItem = false;
|
|
|
|
m_endsSwapped = false;
|
|
|
|
|
|
|
|
const_cast<KIID&>( m_Uuid ) = KIID( msg.id().value() );
|
|
|
|
SetLocked( msg.locked() == kiapi::common::types::LS_LOCKED );
|
|
|
|
SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( msg.layer() ) );
|
|
|
|
SetNetCode( msg.net().code().value() );
|
|
|
|
|
|
|
|
SetFilled( msg.attributes().fill().fill_type() == kiapi::common::types::GFT_FILLED );
|
|
|
|
SetWidth( msg.attributes().stroke().width().value_nm() );
|
|
|
|
|
|
|
|
switch( msg.attributes().stroke().style() )
|
|
|
|
{
|
|
|
|
case kiapi::common::types::SLS_DEFAULT: SetLineStyle( LINE_STYLE::DEFAULT ); break;
|
|
|
|
case kiapi::common::types::SLS_SOLID: SetLineStyle( LINE_STYLE::SOLID ); break;
|
|
|
|
case kiapi::common::types::SLS_DASH: SetLineStyle( LINE_STYLE::DASH ); break;
|
|
|
|
case kiapi::common::types::SLS_DOT: SetLineStyle( LINE_STYLE::DOT ); break;
|
|
|
|
case kiapi::common::types::SLS_DASHDOT: SetLineStyle( LINE_STYLE::DASHDOT ); break;
|
|
|
|
case kiapi::common::types::SLS_DASHDOTDOT: SetLineStyle( LINE_STYLE::DASHDOTDOT ); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( msg.has_segment() )
|
|
|
|
{
|
|
|
|
SetShape( SHAPE_T::SEGMENT );
|
|
|
|
SetStart( kiapi::common::UnpackVector2( msg.segment().start() ) );
|
|
|
|
SetEnd( kiapi::common::UnpackVector2( msg.segment().end() ) );
|
|
|
|
}
|
|
|
|
else if( msg.has_rectangle() )
|
|
|
|
{
|
|
|
|
SetShape( SHAPE_T::RECTANGLE );
|
|
|
|
SetStart( kiapi::common::UnpackVector2( msg.rectangle().top_left() ) );
|
|
|
|
SetEnd( kiapi::common::UnpackVector2( msg.rectangle().bottom_right() ) );
|
|
|
|
}
|
|
|
|
else if( msg.has_arc() )
|
|
|
|
{
|
|
|
|
SetShape( SHAPE_T::ARC );
|
|
|
|
SetArcGeometry( kiapi::common::UnpackVector2( msg.arc().start() ),
|
|
|
|
kiapi::common::UnpackVector2( msg.arc().mid() ),
|
|
|
|
kiapi::common::UnpackVector2( msg.arc().end() ) );
|
|
|
|
}
|
|
|
|
else if( msg.has_circle() )
|
|
|
|
{
|
|
|
|
SetShape( SHAPE_T::CIRCLE );
|
|
|
|
SetStart( kiapi::common::UnpackVector2( msg.circle().center() ) );
|
|
|
|
SetEnd( kiapi::common::UnpackVector2( msg.circle().radius_point() ) );
|
|
|
|
}
|
|
|
|
else if( msg.has_polygon() )
|
|
|
|
{
|
|
|
|
SetShape( SHAPE_T::POLY );
|
|
|
|
const auto& polyMsg = msg.polygon().polygons();
|
|
|
|
|
|
|
|
SHAPE_POLY_SET sps;
|
|
|
|
|
|
|
|
for( const kiapi::common::types::PolygonWithHoles& polygonWithHoles : polyMsg )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET::POLYGON polygon;
|
|
|
|
|
2024-04-04 22:55:58 +00:00
|
|
|
polygon.emplace_back( kiapi::common::UnpackPolyLine( polygonWithHoles.outline() ) );
|
2024-01-20 23:35:29 +00:00
|
|
|
|
|
|
|
for( const kiapi::common::types::PolyLine& holeMsg : polygonWithHoles.holes() )
|
2024-04-04 22:55:58 +00:00
|
|
|
polygon.emplace_back( kiapi::common::UnpackPolyLine( holeMsg ) );
|
2024-01-20 23:35:29 +00:00
|
|
|
|
|
|
|
sps.AddPolygon( polygon );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPolyShape( sps );
|
|
|
|
}
|
|
|
|
else if( msg.has_bezier() )
|
|
|
|
{
|
|
|
|
SetShape( SHAPE_T::BEZIER );
|
|
|
|
SetStart( kiapi::common::UnpackVector2( msg.bezier().start() ) );
|
|
|
|
SetBezierC1( kiapi::common::UnpackVector2( msg.bezier().control1() ) );
|
|
|
|
SetBezierC2( kiapi::common::UnpackVector2( msg.bezier().control2() ) );
|
|
|
|
SetEnd( kiapi::common::UnpackVector2( msg.bezier().end() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
|
2022-09-12 10:38:24 +00:00
|
|
|
bool PCB_SHAPE::IsType( const std::vector<KICAD_T>& aScanTypes ) const
|
|
|
|
{
|
|
|
|
if( BOARD_ITEM::IsType( aScanTypes ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
bool sametype = false;
|
|
|
|
|
|
|
|
for( KICAD_T scanType : aScanTypes )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( scanType == PCB_LOCATE_BOARD_EDGE_T )
|
2022-09-12 10:38:24 +00:00
|
|
|
sametype = m_layer == Edge_Cuts;
|
|
|
|
else if( scanType == PCB_SHAPE_LOCATE_ARC_T )
|
|
|
|
sametype = m_shape == SHAPE_T::ARC;
|
|
|
|
else if( scanType == PCB_SHAPE_LOCATE_CIRCLE_T )
|
|
|
|
sametype = m_shape == SHAPE_T::CIRCLE;
|
|
|
|
else if( scanType == PCB_SHAPE_LOCATE_RECT_T )
|
2023-07-24 16:07:56 +00:00
|
|
|
sametype = m_shape == SHAPE_T::RECTANGLE;
|
2022-09-12 10:38:24 +00:00
|
|
|
else if( scanType == PCB_SHAPE_LOCATE_SEGMENT_T )
|
|
|
|
sametype = m_shape == SHAPE_T::SEGMENT;
|
|
|
|
else if( scanType == PCB_SHAPE_LOCATE_POLY_T )
|
|
|
|
sametype = m_shape == SHAPE_T::POLY;
|
2022-10-31 19:48:23 +00:00
|
|
|
else if( scanType == PCB_SHAPE_LOCATE_BEZIER_T )
|
|
|
|
sametype = m_shape == SHAPE_T::BEZIER;
|
2022-09-12 10:38:24 +00:00
|
|
|
|
|
|
|
if( sametype )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-11 04:01:39 +00:00
|
|
|
bool PCB_SHAPE::IsConnected() const
|
|
|
|
{
|
|
|
|
// Only board-level copper shapes are connectable
|
|
|
|
return IsOnCopperLayer() && !GetParentFootprint();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
void PCB_SHAPE::SetLayer( PCB_LAYER_ID aLayer )
|
|
|
|
{
|
|
|
|
BOARD_ITEM::SetLayer( aLayer );
|
|
|
|
|
|
|
|
if( !IsOnCopperLayer() )
|
|
|
|
SetNetCode( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<VECTOR2I> PCB_SHAPE::GetConnectionPoints() const
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2I> ret;
|
|
|
|
|
|
|
|
// For filled shapes, we may as well use a centroid
|
|
|
|
if( IsFilled() )
|
|
|
|
{
|
|
|
|
ret.emplace_back( GetCenter() );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( m_shape )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
ret.emplace_back( GetArcMid() );
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
|
|
|
case SHAPE_T::SEGMENT:
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
ret.emplace_back( GetStart() );
|
|
|
|
ret.emplace_back( GetEnd() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
for( auto iter = GetPolyShape().CIterate(); iter; ++iter )
|
|
|
|
ret.emplace_back( *iter );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECTANGLE:
|
|
|
|
for( const VECTOR2I& pt : GetRectCorners() )
|
|
|
|
ret.emplace_back( pt );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-14 12:39:35 +00:00
|
|
|
int PCB_SHAPE::GetWidth() const
|
|
|
|
{
|
|
|
|
// A stroke width of 0 in PCBNew means no-border, but negative stroke-widths are only used
|
|
|
|
// in EEschema (see SCH_SHAPE::GetPenWidth()).
|
|
|
|
// Since negative stroke widths can trip up down-stream code (such as the Gerber plotter), we
|
|
|
|
// weed them out here.
|
|
|
|
return std::max( EDA_SHAPE::GetWidth(), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 11:19:43 +00:00
|
|
|
void PCB_SHAPE::StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings )
|
|
|
|
{
|
|
|
|
m_stroke.SetWidth( settings.GetLineThickness( GetLayer() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2021-07-22 08:36:57 +00:00
|
|
|
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;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
if( GetShape() == SHAPE_T::RECTANGLE )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
|
|
|
pts = GetRectCorners();
|
|
|
|
}
|
|
|
|
else if( GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
2022-11-09 00:03:59 +00:00
|
|
|
for( int ii = 0; ii < GetPolyShape().OutlineCount(); ++ii )
|
|
|
|
{
|
|
|
|
for( const VECTOR2I& pt : GetPolyShape().Outline( ii ).CPoints() )
|
2023-03-30 11:49:23 +00:00
|
|
|
pts.emplace_back( pt );
|
2022-11-09 00:03:59 +00:00
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-29 11:23:52 +00:00
|
|
|
void PCB_SHAPE::Normalize()
|
2022-07-07 17:39:10 +00:00
|
|
|
{
|
2023-07-24 16:07:56 +00:00
|
|
|
if( m_shape == SHAPE_T::RECTANGLE )
|
2022-07-07 17:39:10 +00:00
|
|
|
{
|
|
|
|
VECTOR2I start = GetStart();
|
|
|
|
VECTOR2I end = GetEnd();
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I rect( start, end - start );
|
2022-07-07 17:39:10 +00:00
|
|
|
rect.Normalize();
|
|
|
|
|
|
|
|
SetStart( rect.GetPosition() );
|
|
|
|
SetEnd( rect.GetEnd() );
|
|
|
|
}
|
2023-06-05 20:26:11 +00:00
|
|
|
else if( m_shape == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
auto horizontal =
|
|
|
|
[]( const SEG& seg )
|
|
|
|
{
|
|
|
|
return seg.A.y == seg.B.y;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto vertical =
|
|
|
|
[]( const SEG& seg )
|
|
|
|
{
|
|
|
|
return seg.A.x == seg.B.x;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Convert a poly back to a rectangle if appropriate
|
|
|
|
if( m_poly.OutlineCount() == 1 && m_poly.Outline( 0 ).SegmentCount() == 4 )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& outline = m_poly.Outline( 0 );
|
|
|
|
|
|
|
|
if( horizontal( outline.Segment( 0 ) )
|
|
|
|
&& vertical( outline.Segment( 1 ) )
|
|
|
|
&& horizontal( outline.Segment( 2 ) )
|
|
|
|
&& vertical( outline.Segment( 3 ) ) )
|
|
|
|
{
|
2023-07-24 16:07:56 +00:00
|
|
|
m_shape = SHAPE_T::RECTANGLE;
|
2023-06-05 20:26:11 +00:00
|
|
|
m_start.x = std::min( outline.Segment( 0 ).A.x, outline.Segment( 0 ).B.x );
|
|
|
|
m_start.y = std::min( outline.Segment( 1 ).A.y, outline.Segment( 1 ).B.y );
|
|
|
|
m_end.x = std::max( outline.Segment( 0 ).A.x, outline.Segment( 0 ).B.x );
|
|
|
|
m_end.y = std::max( outline.Segment( 1 ).A.y, outline.Segment( 1 ).B.y );
|
|
|
|
}
|
|
|
|
else if( vertical( outline.Segment( 0 ) )
|
|
|
|
&& horizontal( outline.Segment( 1 ) )
|
|
|
|
&& vertical( outline.Segment( 2 ) )
|
|
|
|
&& horizontal( outline.Segment( 3 ) ) )
|
|
|
|
{
|
2023-07-24 16:07:56 +00:00
|
|
|
m_shape = SHAPE_T::RECTANGLE;
|
2023-06-05 20:26:11 +00:00
|
|
|
m_start.x = std::min( outline.Segment( 1 ).A.x, outline.Segment( 1 ).B.x );
|
|
|
|
m_start.y = std::min( outline.Segment( 0 ).A.y, outline.Segment( 0 ).B.y );
|
|
|
|
m_end.x = std::max( outline.Segment( 1 ).A.x, outline.Segment( 1 ).B.x );
|
|
|
|
m_end.y = std::max( outline.Segment( 0 ).A.y, outline.Segment( 0 ).B.y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-07 17:39:10 +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
|
|
|
|
2022-09-22 14:05:06 +00:00
|
|
|
void PCB_SHAPE::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
|
|
|
|
{
|
|
|
|
// Mirror an edge of the footprint. the layer is not modified
|
|
|
|
// This is a footprint shape modification.
|
|
|
|
|
|
|
|
switch( GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
case SHAPE_T::SEGMENT:
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2022-09-22 14:05:06 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
if( aMirrorAroundXAxis )
|
|
|
|
{
|
|
|
|
MIRROR( m_start.y, aCentre.y );
|
|
|
|
MIRROR( m_end.y, aCentre.y );
|
|
|
|
MIRROR( m_arcCenter.y, aCentre.y );
|
|
|
|
MIRROR( m_bezierC1.y, aCentre.y );
|
|
|
|
MIRROR( m_bezierC2.y, aCentre.y );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MIRROR( m_start.x, aCentre.x );
|
|
|
|
MIRROR( m_end.x, aCentre.x );
|
|
|
|
MIRROR( m_arcCenter.x, aCentre.x );
|
|
|
|
MIRROR( m_bezierC1.x, aCentre.x );
|
|
|
|
MIRROR( m_bezierC2.x, aCentre.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::ARC )
|
|
|
|
std::swap( m_start, m_end );
|
|
|
|
|
|
|
|
if( GetShape() == SHAPE_T::BEZIER )
|
|
|
|
RebuildBezierToSegmentsPointsList( GetWidth() );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
m_poly.Mirror( !aMirrorAroundXAxis, aMirrorAroundXAxis, aCentre );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( SHAPE_T_asString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
void PCB_SHAPE::SetIsProxyItem( bool aIsProxy )
|
2023-09-04 19:48:34 +00:00
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
PAD* parentPad = nullptr;
|
2023-09-04 19:48:34 +00:00
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
if( GetBoard() && GetBoard()->IsFootprintHolder() )
|
|
|
|
{
|
|
|
|
for( FOOTPRINT* fp : GetBoard()->Footprints() )
|
|
|
|
{
|
|
|
|
for( PAD* pad : fp->Pads() )
|
|
|
|
{
|
|
|
|
if( pad->IsEntered() )
|
|
|
|
{
|
|
|
|
parentPad = pad;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aIsProxy && !m_proxyItem )
|
|
|
|
{
|
|
|
|
if( GetShape() == SHAPE_T::SEGMENT )
|
|
|
|
{
|
|
|
|
if( parentPad && parentPad->GetThermalSpokeWidth() )
|
|
|
|
SetWidth( parentPad->GetThermalSpokeWidth() );
|
|
|
|
else
|
|
|
|
SetWidth( pcbIUScale.mmToIU( ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetWidth( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( m_proxyItem && !aIsProxy )
|
|
|
|
{
|
|
|
|
SetWidth( pcbIUScale.mmToIU( DEFAULT_LINE_WIDTH ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_proxyItem = aIsProxy;
|
2023-09-04 19:48:34 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( FOOTPRINT* parent = GetParentFootprint() )
|
|
|
|
{
|
2023-08-04 10:13:20 +00:00
|
|
|
if( parent->GetLayer() == F_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_FR ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
return HIDE;
|
|
|
|
|
2023-08-04 10:13:20 +00:00
|
|
|
if( parent->GetLayer() == B_Cu && !aView->IsLayerVisible( LAYER_FOOTPRINTS_BK ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
return HIDE;
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:03:06 +00:00
|
|
|
return SHOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
void PCB_SHAPE::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aLayers[0] = GetLayer();
|
|
|
|
|
|
|
|
if( IsOnCopperLayer() )
|
|
|
|
{
|
|
|
|
aLayers[1] = GetNetnameLayer( aLayers[0] );
|
|
|
|
aCount = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( IsLocked() )
|
|
|
|
aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( aFrame->GetName() == PCB_EDIT_FRAME_NAME )
|
|
|
|
{
|
|
|
|
if( FOOTPRINT* parent = GetParentFootprint() )
|
|
|
|
aList.emplace_back( _( "Footprint" ), parent->GetReference() );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString PCB_SHAPE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2020-08-09 23:03:31 +00:00
|
|
|
{
|
2023-07-30 19:39:07 +00:00
|
|
|
if( GetNetCode() > 0 )
|
|
|
|
{
|
|
|
|
return wxString::Format( _( "%s %s on %s" ), GetFriendlyName(), GetNetnameMsg(),
|
|
|
|
GetLayerName() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return wxString::Format( _( "%s on %s" ), GetFriendlyName(), 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
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( GetParentFootprint() )
|
|
|
|
return BITMAPS::show_mod_edge;
|
|
|
|
else
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-11 17:09:25 +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 );
|
2023-06-03 11:28:03 +00:00
|
|
|
wxCHECK( image, /* void */ );
|
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
|
|
|
|
2023-01-18 07:34:52 +00:00
|
|
|
// Swap params not handled by SwapShape( image )
|
2020-11-14 14:29:11 +00:00
|
|
|
std::swap( m_layer, image->m_layer );
|
2023-01-22 12:52:41 +00:00
|
|
|
std::swap( m_isKnockout, image->m_isKnockout );
|
|
|
|
std::swap( m_isLocked, image->m_isLocked );
|
2020-11-14 18:11:28 +00:00
|
|
|
std::swap( m_flags, image->m_flags );
|
|
|
|
std::swap( m_parent, image->m_parent );
|
2020-08-02 10:54:25 +00:00
|
|
|
std::swap( m_forceVisible, image->m_forceVisible );
|
2023-08-14 16:15:05 +00:00
|
|
|
std::swap( m_netinfo, image->m_netinfo );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
void PCB_SHAPE::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
|
|
|
|
int aClearance, int aError, ERROR_LOC aErrorLoc,
|
|
|
|
bool ignoreLineWidth ) const
|
2021-10-25 19:50:33 +00:00
|
|
|
{
|
2022-10-21 12:48:45 +00:00
|
|
|
EDA_SHAPE::TransformShapeToPolygon( aBuffer, aClearance, aError, aErrorLoc, ignoreLineWidth );
|
2021-10-25 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
bool PCB_SHAPE::operator==( const BOARD_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const PCB_SHAPE& other = static_cast<const PCB_SHAPE&>( aOther );
|
|
|
|
|
|
|
|
if( m_layer != other.m_layer )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_isKnockout != other.m_isKnockout )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_isLocked != other.m_isLocked )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_flags != other.m_flags )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_forceVisible != other.m_forceVisible )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_netinfo->GetNetCode() != other.m_netinfo->GetNetCode() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return EDA_SHAPE::operator==( other );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double PCB_SHAPE::Similarity( const BOARD_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( aOther.Type() != Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const PCB_SHAPE& other = static_cast<const PCB_SHAPE&>( aOther );
|
|
|
|
|
|
|
|
double similarity = 1.0;
|
|
|
|
|
|
|
|
if( GetLayer() != other.GetLayer() )
|
|
|
|
similarity *= 0.9;
|
|
|
|
|
|
|
|
if( m_isKnockout != other.m_isKnockout )
|
|
|
|
similarity *= 0.9;
|
|
|
|
|
|
|
|
if( m_isLocked != other.m_isLocked )
|
|
|
|
similarity *= 0.9;
|
|
|
|
|
|
|
|
if( m_flags != other.m_flags )
|
|
|
|
similarity *= 0.9;
|
|
|
|
|
|
|
|
if( m_forceVisible != other.m_forceVisible )
|
|
|
|
similarity *= 0.9;
|
|
|
|
|
|
|
|
if( m_netinfo->GetNetCode() != other.m_netinfo->GetNetCode() )
|
|
|
|
similarity *= 0.9;
|
|
|
|
|
|
|
|
similarity *= EDA_SHAPE::Similarity( other );
|
|
|
|
|
|
|
|
return similarity;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
2023-07-30 19:39:07 +00:00
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_SHAPE, BOARD_CONNECTED_ITEM> );
|
2021-07-14 20:03:32 +00:00
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_SHAPE, EDA_SHAPE> );
|
2023-07-30 19:39:07 +00:00
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( BOARD_CONNECTED_ITEM ) );
|
2021-07-14 20:03:32 +00:00
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( EDA_SHAPE ) );
|
2022-08-29 21:13:30 +00:00
|
|
|
|
2023-05-29 18:38:20 +00:00
|
|
|
// Need to initialise enum_map before we can use a Property enum for it
|
|
|
|
ENUM_MAP<PCB_LAYER_ID>& layerEnum = ENUM_MAP<PCB_LAYER_ID>::Instance();
|
|
|
|
|
|
|
|
if( layerEnum.Choices().GetCount() == 0 )
|
|
|
|
{
|
|
|
|
layerEnum.Undefined( UNDEFINED_LAYER );
|
|
|
|
|
|
|
|
for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
|
|
|
|
layerEnum.Map( *seq, LSET::Name( *seq ) );
|
|
|
|
}
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
void ( PCB_SHAPE::*shapeLayerSetter )( PCB_LAYER_ID ) = &PCB_SHAPE::SetLayer;
|
|
|
|
PCB_LAYER_ID ( PCB_SHAPE::*shapeLayerGetter )() const = &PCB_SHAPE::GetLayer;
|
|
|
|
|
|
|
|
auto layerProperty = new PROPERTY_ENUM<PCB_SHAPE, PCB_LAYER_ID>(
|
|
|
|
_HKI( "Layer" ), shapeLayerSetter, shapeLayerGetter );
|
2022-08-29 21:13:30 +00:00
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
propMgr.ReplaceProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ), layerProperty );
|
2023-02-24 01:23:44 +00:00
|
|
|
|
|
|
|
// Only polygons have meaningful Position properties.
|
|
|
|
// On other shapes, these are duplicates of the Start properties.
|
|
|
|
auto isPolygon =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( aItem ) )
|
|
|
|
return shape->GetShape() == SHAPE_T::POLY;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( BOARD_ITEM ),
|
|
|
|
_HKI( "Position X" ), isPolygon );
|
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( BOARD_ITEM ),
|
|
|
|
_HKI( "Position Y" ), isPolygon );
|
2023-07-30 19:39:07 +00:00
|
|
|
|
2023-10-30 17:29:38 +00:00
|
|
|
propMgr.Mask( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
|
|
|
|
propMgr.Mask( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( EDA_SHAPE ), _HKI( "Fill Color" ) );
|
|
|
|
|
2023-07-30 19:39:07 +00:00
|
|
|
auto isCopper =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( aItem ) )
|
|
|
|
return shape->IsOnCopperLayer();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
propMgr.OverrideAvailability( TYPE_HASH( PCB_SHAPE ), TYPE_HASH( BOARD_CONNECTED_ITEM ),
|
|
|
|
_HKI( "Net" ), isCopper );
|
2023-09-04 18:44:39 +00:00
|
|
|
|
|
|
|
auto isPadEditMode =
|
2023-09-13 10:27:04 +00:00
|
|
|
[]( BOARD* aBoard ) -> bool
|
2023-09-04 18:44:39 +00:00
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
if( aBoard && aBoard->IsFootprintHolder() )
|
2023-09-04 18:44:39 +00:00
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
for( FOOTPRINT* fp : aBoard->Footprints() )
|
2023-09-04 18:44:39 +00:00
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
for( PAD* pad : fp->Pads() )
|
2023-09-04 18:44:39 +00:00
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
if( pad->IsEntered() )
|
|
|
|
return true;
|
2023-09-04 18:44:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
auto showNumberBoxProperty =
|
|
|
|
[&]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( aItem ) )
|
|
|
|
{
|
|
|
|
if( shape->GetShape() == SHAPE_T::RECTANGLE )
|
|
|
|
return isPadEditMode( shape->GetBoard() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto showSpokeTemplateProperty =
|
|
|
|
[&]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( aItem ) )
|
|
|
|
{
|
|
|
|
if( shape->GetShape() == SHAPE_T::SEGMENT )
|
|
|
|
return isPadEditMode( shape->GetBoard() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2023-09-04 18:44:39 +00:00
|
|
|
const wxString groupPadPrimitives = _HKI( "Pad Primitives" );
|
|
|
|
|
2023-09-04 19:48:34 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_SHAPE, bool>( _HKI( "Number Box" ),
|
2023-09-13 10:27:04 +00:00
|
|
|
&PCB_SHAPE::SetIsProxyItem,
|
|
|
|
&PCB_SHAPE::IsProxyItem ),
|
|
|
|
groupPadPrimitives )
|
2023-11-23 20:22:15 +00:00
|
|
|
.SetAvailableFunc( showNumberBoxProperty )
|
|
|
|
.SetIsHiddenFromRulesEditor();
|
2023-09-13 10:27:04 +00:00
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_SHAPE, bool>( _HKI( "Thermal Spoke Template" ),
|
|
|
|
&PCB_SHAPE::SetIsProxyItem,
|
|
|
|
&PCB_SHAPE::IsProxyItem ),
|
2023-09-04 18:44:39 +00:00
|
|
|
groupPadPrimitives )
|
2023-11-23 20:22:15 +00:00
|
|
|
.SetAvailableFunc( showSpokeTemplateProperty )
|
|
|
|
.SetIsHiddenFromRulesEditor();
|
2020-02-02 18:40:14 +00:00
|
|
|
}
|
2021-07-14 20:03:32 +00:00
|
|
|
} _PCB_SHAPE_DESC;
|