2016-08-15 15:16:47 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2016-08-15 15:16:48 +00:00
|
|
|
* Copyright (C) 2013-2016 CERN
|
2019-05-17 00:13:21 +00:00
|
|
|
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-08-15 15:16:47 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2018-02-02 20:57:12 +00:00
|
|
|
#include <board_connected_item.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_text.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
|
|
|
#include <track.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_text.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2016-08-15 15:16:47 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
#include <geometry/convex_hull.h>
|
2018-02-22 10:19:33 +00:00
|
|
|
#include <confirm.h>
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_item.h>
|
|
|
|
#include <view/view_group.h>
|
|
|
|
|
|
|
|
#include <pcb_painter.h>
|
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
2018-02-04 12:09:30 +00:00
|
|
|
#include <geometry/shape_arc.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <geometry/shape_simple.h>
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2020-10-08 21:57:08 +00:00
|
|
|
#include <drc/drc_rule.h>
|
|
|
|
#include <drc/drc_engine.h>
|
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2020-07-03 23:33:36 +00:00
|
|
|
#include <advanced_config.h>
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
#include "tools/pcb_tool_base.h"
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
#include "pns_kicad_iface.h"
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
#include "pns_arc.h"
|
2016-08-15 15:16:47 +00:00
|
|
|
#include "pns_routing_settings.h"
|
2020-10-08 22:01:09 +00:00
|
|
|
#include "pns_sizes_settings.h"
|
2016-08-15 15:16:47 +00:00
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_segment.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_router.h"
|
2016-08-15 15:16:48 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2016-08-15 15:16:47 +00:00
|
|
|
#include "router_preview_item.h"
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
typedef VECTOR2I::extended_type ecoord;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class PNS_PCBNEW_RULE_RESOLVER : public PNS::RULE_RESOLVER
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-04-16 22:29:28 +00:00
|
|
|
PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER_IFACE* aRouterIface );
|
2016-08-15 15:16:47 +00:00
|
|
|
virtual ~PNS_PCBNEW_RULE_RESOLVER();
|
|
|
|
|
2020-10-08 21:57:08 +00:00
|
|
|
virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) override;
|
2021-01-01 00:29:05 +00:00
|
|
|
virtual int HoleClearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) override;
|
|
|
|
virtual int HoleToHoleClearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) override;
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual int DpCoupledNet( int aNet ) override;
|
|
|
|
virtual int DpNetPolarity( int aNet ) override;
|
2020-10-08 22:01:09 +00:00
|
|
|
virtual bool DpNetPair( const PNS::ITEM* aItem, int& aNetP, int& aNetN ) override;
|
|
|
|
virtual bool IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM* aB ) override;
|
2019-07-24 15:19:03 +00:00
|
|
|
|
2021-01-05 16:41:35 +00:00
|
|
|
virtual bool QueryConstraint( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA,
|
|
|
|
const PNS::ITEM* aItemB, int aLayer,
|
|
|
|
PNS::CONSTRAINT* aConstraint ) override;
|
2018-05-19 00:50:52 +00:00
|
|
|
virtual wxString NetName( int aNet ) override;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
private:
|
2019-07-24 15:19:03 +00:00
|
|
|
int holeRadius( const PNS::ITEM* aItem ) const;
|
2019-07-21 22:35:22 +00:00
|
|
|
int matchDpSuffix( const wxString& aNetName, wxString& aComplementNet, wxString& aBaseDpName );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2020-11-11 15:30:37 +00:00
|
|
|
private:
|
2020-04-16 22:29:28 +00:00
|
|
|
PNS::ROUTER_IFACE* m_routerIface;
|
2020-10-31 15:33:02 +00:00
|
|
|
BOARD* m_board;
|
|
|
|
TRACK m_dummyTrack;
|
|
|
|
ARC m_dummyArc;
|
|
|
|
VIA m_dummyVia;
|
2020-11-11 15:30:37 +00:00
|
|
|
|
|
|
|
std::map<std::pair<const PNS::ITEM*, const PNS::ITEM*>, int> m_clearanceCache;
|
2021-01-01 00:29:05 +00:00
|
|
|
std::map<std::pair<const PNS::ITEM*, const PNS::ITEM*>, int> m_holeClearanceCache;
|
|
|
|
std::map<std::pair<const PNS::ITEM*, const PNS::ITEM*>, int> m_holeToHoleClearanceCache;
|
2016-08-15 15:16:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-31 15:33:02 +00:00
|
|
|
PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard,
|
|
|
|
PNS::ROUTER_IFACE* aRouterIface ) :
|
2020-04-16 22:29:28 +00:00
|
|
|
m_routerIface( aRouterIface ),
|
2020-10-31 15:33:02 +00:00
|
|
|
m_board( aBoard ),
|
|
|
|
m_dummyTrack( aBoard ),
|
|
|
|
m_dummyArc( aBoard ),
|
|
|
|
m_dummyVia( aBoard )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::holeRadius( const PNS::ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
if( aItem->Kind() == PNS::ITEM::SOLID_T )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
const PAD* pad = dynamic_cast<const PAD*>( aItem->Parent() );
|
2019-07-24 15:19:03 +00:00
|
|
|
|
|
|
|
if( pad && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
|
|
|
|
return pad->GetDrillSize().x / 2;
|
|
|
|
}
|
|
|
|
else if( aItem->Kind() == PNS::ITEM::VIA_T )
|
|
|
|
{
|
|
|
|
const ::VIA* via = dynamic_cast<const ::VIA*>( aItem->Parent() );
|
|
|
|
|
|
|
|
if( via )
|
|
|
|
return via->GetDrillValue() / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-08 22:01:09 +00:00
|
|
|
bool PNS_PCBNEW_RULE_RESOLVER::IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM* aB )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-10-08 22:01:09 +00:00
|
|
|
int net_p, net_n;
|
2016-10-18 15:40:22 +00:00
|
|
|
|
2020-10-09 00:38:08 +00:00
|
|
|
if( !DpNetPair( aA, net_p, net_n ) )
|
|
|
|
return false;
|
2016-10-18 15:40:22 +00:00
|
|
|
|
2020-10-08 22:01:09 +00:00
|
|
|
if( aA->Net() == net_p && aB->Net() == net_n )
|
|
|
|
return true;
|
|
|
|
if( aB->Net() == net_p && aA->Net() == net_n )
|
|
|
|
return true;
|
2016-10-18 15:40:22 +00:00
|
|
|
|
2020-10-08 22:01:09 +00:00
|
|
|
return false;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 22:01:09 +00:00
|
|
|
|
2021-01-02 16:32:03 +00:00
|
|
|
bool isCopper( const PNS::ITEM* aItem )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* parent = aItem->Parent();
|
|
|
|
|
|
|
|
if( parent && parent->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
PAD* pad = static_cast<PAD*>( parent );
|
|
|
|
return pad->IsOnCopperLayer() && pad->GetAttribute() != PAD_ATTRIB_NPTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
bool isEdge( const PNS::ITEM* aItem )
|
|
|
|
{
|
2021-02-11 22:07:15 +00:00
|
|
|
const BOARD_ITEM *parent = aItem->Parent();
|
|
|
|
|
|
|
|
if( parent )
|
|
|
|
{
|
|
|
|
return parent->GetLayer() == Edge_Cuts || parent->GetLayer () == Margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 22:01:09 +00:00
|
|
|
|
2020-10-10 18:29:41 +00:00
|
|
|
bool PNS_PCBNEW_RULE_RESOLVER::QueryConstraint( PNS::CONSTRAINT_TYPE aType,
|
|
|
|
const PNS::ITEM* aItemA, const PNS::ITEM* aItemB,
|
|
|
|
int aLayer, PNS::CONSTRAINT* aConstraint )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-10-08 21:57:08 +00:00
|
|
|
std::shared_ptr<DRC_ENGINE> drcEngine = m_board->GetDesignSettings().m_DRCEngine;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2020-10-08 21:57:08 +00:00
|
|
|
if( !drcEngine )
|
|
|
|
return false;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
DRC_CONSTRAINT_T hostType;
|
2016-10-18 15:40:22 +00:00
|
|
|
|
2020-10-08 21:57:08 +00:00
|
|
|
switch ( aType )
|
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
case PNS::CONSTRAINT_TYPE::CT_CLEARANCE: hostType = CLEARANCE_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_WIDTH: hostType = TRACK_WIDTH_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_DIFF_PAIR_GAP: hostType = DIFF_PAIR_GAP_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_LENGTH: hostType = LENGTH_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_VIA_DIAMETER: hostType = VIA_DIAMETER_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_VIA_HOLE: hostType = HOLE_SIZE_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_HOLE_CLEARANCE: hostType = HOLE_CLEARANCE_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_EDGE_CLEARANCE: hostType = EDGE_CLEARANCE_CONSTRAINT; break;
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_HOLE_TO_HOLE: hostType = HOLE_TO_HOLE_CONSTRAINT; break;
|
|
|
|
default: return false; // should not happen
|
2020-10-08 21:57:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 23:23:23 +00:00
|
|
|
BOARD_ITEM* parentA = aItemA ? aItemA->Parent() : nullptr;
|
|
|
|
BOARD_ITEM* parentB = aItemB ? aItemB->Parent() : nullptr;
|
|
|
|
DRC_CONSTRAINT hostConstraint;
|
2020-10-12 19:55:36 +00:00
|
|
|
|
2020-10-31 15:33:02 +00:00
|
|
|
// A track being routed may not have a BOARD_ITEM associated yet.
|
2020-11-11 00:18:35 +00:00
|
|
|
if( aItemA && !parentA )
|
2020-10-12 19:55:36 +00:00
|
|
|
{
|
|
|
|
switch( aItemA->Kind() )
|
|
|
|
{
|
2020-10-31 23:23:23 +00:00
|
|
|
case PNS::ITEM::ARC_T: parentA = &m_dummyArc; break;
|
|
|
|
case PNS::ITEM::VIA_T: parentA = &m_dummyVia; break;
|
|
|
|
case PNS::ITEM::SEGMENT_T: parentA = &m_dummyTrack; break;
|
|
|
|
case PNS::ITEM::LINE_T: parentA = &m_dummyTrack; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( parentA )
|
|
|
|
{
|
|
|
|
parentA->SetLayer( (PCB_LAYER_ID) aLayer );
|
2020-12-20 20:35:31 +00:00
|
|
|
static_cast<BOARD_CONNECTED_ITEM*>( parentA )->SetNetCode( aItemA->Net(), true );
|
2020-10-31 23:23:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aItemB && !parentB )
|
|
|
|
{
|
|
|
|
switch( aItemB->Kind() )
|
|
|
|
{
|
|
|
|
case PNS::ITEM::ARC_T: parentB = &m_dummyArc; break;
|
|
|
|
case PNS::ITEM::VIA_T: parentB = &m_dummyVia; break;
|
|
|
|
case PNS::ITEM::SEGMENT_T: parentB = &m_dummyTrack; break;
|
|
|
|
case PNS::ITEM::LINE_T: parentB = &m_dummyTrack; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( parentB )
|
|
|
|
{
|
|
|
|
parentB->SetLayer( (PCB_LAYER_ID) aLayer );
|
2020-12-20 20:35:31 +00:00
|
|
|
static_cast<BOARD_CONNECTED_ITEM*>( parentB )->SetNetCode( aItemB->Net(), true );
|
2020-10-12 19:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-08 22:01:09 +00:00
|
|
|
|
2020-10-12 19:55:36 +00:00
|
|
|
if( parentA )
|
2021-02-08 14:53:49 +00:00
|
|
|
hostConstraint = drcEngine->EvalRules( hostType, parentA, parentB, (PCB_LAYER_ID) aLayer );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2020-10-08 21:57:08 +00:00
|
|
|
if( hostConstraint.IsNull() )
|
|
|
|
return false;
|
2020-10-08 22:01:09 +00:00
|
|
|
|
|
|
|
switch ( aType )
|
|
|
|
{
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_CLEARANCE:
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_WIDTH:
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_DIFF_PAIR_GAP:
|
2020-10-10 18:29:41 +00:00
|
|
|
case PNS::CONSTRAINT_TYPE::CT_VIA_DIAMETER:
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_VIA_HOLE:
|
2021-01-01 00:29:05 +00:00
|
|
|
case PNS::CONSTRAINT_TYPE::CT_HOLE_CLEARANCE:
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_EDGE_CLEARANCE:
|
|
|
|
case PNS::CONSTRAINT_TYPE::CT_HOLE_TO_HOLE:
|
2020-10-08 22:01:09 +00:00
|
|
|
aConstraint->m_Value = hostConstraint.GetValue();
|
2020-10-09 13:26:09 +00:00
|
|
|
aConstraint->m_RuleName = hostConstraint.GetName();
|
2020-10-08 22:01:09 +00:00
|
|
|
aConstraint->m_Type = aType;
|
|
|
|
return true;
|
|
|
|
|
2020-10-11 10:19:07 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-08 21:57:08 +00:00
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB )
|
2017-01-25 09:33:49 +00:00
|
|
|
{
|
2020-11-11 15:30:37 +00:00
|
|
|
std::pair<const PNS::ITEM*, const PNS::ITEM*> key( aA, aB );
|
|
|
|
auto it = m_clearanceCache.find( key );
|
|
|
|
|
|
|
|
if( it != m_clearanceCache.end() )
|
|
|
|
return it->second;
|
|
|
|
|
2020-10-08 21:57:08 +00:00
|
|
|
PNS::CONSTRAINT constraint;
|
2020-10-11 10:19:07 +00:00
|
|
|
int rv = 0;
|
2021-02-25 22:56:34 +00:00
|
|
|
int layer;
|
|
|
|
|
|
|
|
if( !aA->Layers().IsMultilayer() || !aB || aB->Layers().IsMultilayer() )
|
|
|
|
layer = aA->Layer();
|
|
|
|
else
|
|
|
|
layer = aB->Layer();
|
2020-10-08 22:01:09 +00:00
|
|
|
|
2021-01-02 16:32:03 +00:00
|
|
|
if( isCopper( aA ) && ( !aB || isCopper( aB ) ) )
|
2021-01-01 00:29:05 +00:00
|
|
|
{
|
2021-02-25 22:56:34 +00:00
|
|
|
if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_CLEARANCE, aA, aB, layer, &constraint ) )
|
|
|
|
rv = constraint.m_Value.Min();
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( isEdge( aA ) || ( aB && isEdge( aB ) ) )
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
2021-02-25 22:56:34 +00:00
|
|
|
if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_EDGE_CLEARANCE, aA, aB, layer, &constraint ) )
|
2020-10-18 19:58:03 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
if( constraint.m_Value.Min() > rv )
|
|
|
|
rv = constraint.m_Value.Min();
|
2020-10-18 19:58:03 +00:00
|
|
|
}
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
2020-10-08 21:57:08 +00:00
|
|
|
|
2020-11-11 15:30:37 +00:00
|
|
|
m_clearanceCache[ key ] = rv;
|
2021-01-01 00:29:05 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2020-10-08 21:57:08 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
|
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::HoleClearance( const PNS::ITEM* aA, const PNS::ITEM* aB )
|
|
|
|
{
|
|
|
|
std::pair<const PNS::ITEM*, const PNS::ITEM*> key( aA, aB );
|
|
|
|
auto it = m_holeClearanceCache.find( key );
|
|
|
|
|
|
|
|
if( it != m_holeClearanceCache.end() )
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
PNS::CONSTRAINT constraint;
|
|
|
|
int rv = 0;
|
2021-02-25 22:56:34 +00:00
|
|
|
int layer;
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2021-02-25 22:56:34 +00:00
|
|
|
if( !aA->Layers().IsMultilayer() || !aB || aB->Layers().IsMultilayer() )
|
|
|
|
layer = aA->Layer();
|
|
|
|
else
|
|
|
|
layer = aB->Layer();
|
|
|
|
|
|
|
|
if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_HOLE_CLEARANCE, aA, aB, layer, &constraint ) )
|
2021-01-01 00:29:05 +00:00
|
|
|
rv = constraint.m_Value.Min();
|
|
|
|
|
|
|
|
m_holeClearanceCache[ key ] = rv;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::HoleToHoleClearance( const PNS::ITEM* aA, const PNS::ITEM* aB )
|
|
|
|
{
|
|
|
|
std::pair<const PNS::ITEM*, const PNS::ITEM*> key( aA, aB );
|
|
|
|
auto it = m_holeToHoleClearanceCache.find( key );
|
|
|
|
|
|
|
|
if( it != m_holeToHoleClearanceCache.end() )
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
PNS::CONSTRAINT constraint;
|
|
|
|
int rv = 0;
|
2021-02-25 22:56:34 +00:00
|
|
|
int layer;
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2021-02-25 22:56:34 +00:00
|
|
|
if( !aA->Layers().IsMultilayer() || !aB || aB->Layers().IsMultilayer() )
|
|
|
|
layer = aA->Layer();
|
|
|
|
else
|
|
|
|
layer = aB->Layer();
|
|
|
|
|
|
|
|
if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_HOLE_TO_HOLE, aA, aB, layer, &constraint ) )
|
2021-01-01 00:29:05 +00:00
|
|
|
rv = constraint.m_Value.Min();
|
|
|
|
|
|
|
|
m_holeToHoleClearanceCache[ key ] = rv;
|
2020-10-08 22:01:09 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 10:54:28 +00:00
|
|
|
bool PNS_KICAD_IFACE_BASE::inheritTrackWidth( PNS::ITEM* aItem, int* aInheritedWidth )
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
|
|
|
VECTOR2I p;
|
|
|
|
|
|
|
|
assert( aItem->Owner() != NULL );
|
|
|
|
|
|
|
|
switch( aItem->Kind() )
|
|
|
|
{
|
|
|
|
case PNS::ITEM::VIA_T:
|
|
|
|
p = static_cast<PNS::VIA*>( aItem )->Pos();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS::ITEM::SOLID_T:
|
|
|
|
p = static_cast<PNS::SOLID*>( aItem )->Pos();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS::ITEM::SEGMENT_T:
|
2020-10-18 10:54:28 +00:00
|
|
|
*aInheritedWidth = static_cast<PNS::SEGMENT*>( aItem )->Width();
|
|
|
|
return true;
|
2020-10-08 22:01:09 +00:00
|
|
|
|
|
|
|
default:
|
2020-10-18 10:54:28 +00:00
|
|
|
return false;
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PNS::JOINT* jt = static_cast<PNS::NODE*>( aItem->Owner() )->FindJoint( p, aItem );
|
|
|
|
|
|
|
|
assert( jt != NULL );
|
|
|
|
|
|
|
|
int mval = INT_MAX;
|
|
|
|
|
|
|
|
PNS::ITEM_SET linkedSegs = jt->Links();
|
|
|
|
linkedSegs.ExcludeItem( aItem ).FilterKinds( PNS::ITEM::SEGMENT_T );
|
|
|
|
|
|
|
|
for( PNS::ITEM* item : linkedSegs.Items() )
|
|
|
|
{
|
|
|
|
int w = static_cast<PNS::SEGMENT*>( item )->Width();
|
|
|
|
mval = std::min( w, mval );
|
|
|
|
}
|
|
|
|
|
2020-10-18 10:54:28 +00:00
|
|
|
if( mval == INT_MAX )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*aInheritedWidth = mval;
|
|
|
|
return true;
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PNS_KICAD_IFACE_BASE::ImportSizes( PNS::SIZES_SETTINGS& aSizes, PNS::ITEM* aStartItem, int aNet )
|
|
|
|
{
|
2020-10-11 10:19:07 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
PNS::CONSTRAINT constraint;
|
2020-10-08 22:01:09 +00:00
|
|
|
|
2020-10-18 10:54:28 +00:00
|
|
|
int trackWidth = bds.m_TrackMinWidth;
|
|
|
|
bool found = false;
|
2020-10-08 22:01:09 +00:00
|
|
|
|
|
|
|
if( bds.m_UseConnectedTrackWidth && aStartItem != nullptr )
|
|
|
|
{
|
2020-10-18 10:54:28 +00:00
|
|
|
found = inheritTrackWidth( aStartItem, &trackWidth );
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
2020-10-17 12:56:20 +00:00
|
|
|
|
2020-10-18 10:54:28 +00:00
|
|
|
if( !found && bds.UseNetClassTrack() && aStartItem )
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
2020-10-11 10:19:07 +00:00
|
|
|
if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_WIDTH, aStartItem, nullptr,
|
|
|
|
aStartItem->Layer(), &constraint ) )
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
2020-11-17 17:41:57 +00:00
|
|
|
trackWidth = constraint.m_Value.Opt();
|
2020-10-18 10:54:28 +00:00
|
|
|
found = true; // Note: allowed to override anything, including bds.m_TrackMinWidth
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-17 12:56:20 +00:00
|
|
|
|
2020-10-18 10:54:28 +00:00
|
|
|
if( !found )
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
|
|
|
trackWidth = bds.GetCurrentTrackWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
aSizes.SetTrackWidth( trackWidth );
|
|
|
|
|
2020-10-11 10:19:07 +00:00
|
|
|
int viaDiameter = bds.m_ViasMinSize;
|
|
|
|
int viaDrill = bds.m_MinThroughDrill;
|
2020-10-08 22:01:09 +00:00
|
|
|
|
2020-10-10 23:14:12 +00:00
|
|
|
if( bds.UseNetClassVia() && aStartItem ) // netclass value
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
2020-10-11 10:19:07 +00:00
|
|
|
if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_VIA_DIAMETER, aStartItem,
|
|
|
|
nullptr, aStartItem->Layer(), &constraint ) )
|
2020-10-10 18:29:41 +00:00
|
|
|
{
|
2020-11-17 17:41:57 +00:00
|
|
|
viaDiameter = constraint.m_Value.Opt();
|
2020-10-10 18:29:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-11 10:19:07 +00:00
|
|
|
if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_VIA_HOLE, aStartItem,
|
|
|
|
nullptr, aStartItem->Layer(), &constraint ) )
|
2020-10-10 18:29:41 +00:00
|
|
|
{
|
2020-11-17 17:41:57 +00:00
|
|
|
viaDrill = constraint.m_Value.Opt();
|
2020-10-10 18:29:41 +00:00
|
|
|
}
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
viaDiameter = bds.GetCurrentViaSize();
|
|
|
|
viaDrill = bds.GetCurrentViaDrill();
|
|
|
|
}
|
|
|
|
|
|
|
|
aSizes.SetViaDiameter( viaDiameter );
|
|
|
|
aSizes.SetViaDrill( viaDrill );
|
|
|
|
|
2020-10-11 10:19:07 +00:00
|
|
|
int diffPairWidth = bds.m_TrackMinWidth;
|
|
|
|
int diffPairGap = bds.m_MinClearance;
|
|
|
|
int diffPairViaGap = bds.m_MinClearance;
|
2020-10-08 22:01:09 +00:00
|
|
|
|
2020-10-09 00:38:08 +00:00
|
|
|
if( bds.UseNetClassDiffPair() && aStartItem )
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
2020-10-11 10:19:07 +00:00
|
|
|
if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_WIDTH, aStartItem,
|
|
|
|
nullptr, aStartItem->Layer(), &constraint ) )
|
|
|
|
{
|
2020-11-17 17:41:57 +00:00
|
|
|
diffPairWidth = constraint.m_Value.Opt();
|
2020-10-11 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_DIFF_PAIR_GAP, aStartItem,
|
|
|
|
nullptr, aStartItem->Layer(), &constraint ) )
|
|
|
|
{
|
2020-11-17 17:41:57 +00:00
|
|
|
diffPairGap = constraint.m_Value.Opt();
|
|
|
|
diffPairViaGap = constraint.m_Value.Opt();
|
2020-10-11 10:19:07 +00:00
|
|
|
}
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
2021-03-02 12:11:45 +00:00
|
|
|
else
|
2020-10-08 22:01:09 +00:00
|
|
|
{
|
2021-03-02 12:11:45 +00:00
|
|
|
diffPairWidth = bds.GetCurrentDiffPairWidth();
|
|
|
|
diffPairGap = bds.GetCurrentDiffPairGap();
|
|
|
|
diffPairViaGap = bds.GetCurrentDiffPairViaGap();
|
2020-10-08 22:01:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-11 10:19:07 +00:00
|
|
|
//printf( "DPWidth: %d gap %d\n", diffPairWidth, diffPairGap );
|
2020-10-08 22:01:09 +00:00
|
|
|
|
|
|
|
aSizes.SetDiffPairWidth( diffPairWidth );
|
|
|
|
aSizes.SetDiffPairGap( diffPairGap );
|
|
|
|
aSizes.SetDiffPairViaGap( diffPairViaGap );
|
|
|
|
|
2021-02-25 14:21:50 +00:00
|
|
|
int holeToHoleMin = bds.m_HoleToHoleMin;
|
|
|
|
PNS::VIA dummyVia;
|
|
|
|
|
|
|
|
if( m_ruleResolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_HOLE_TO_HOLE, &dummyVia,
|
|
|
|
&dummyVia, UNDEFINED_LAYER, &constraint ) )
|
|
|
|
{
|
|
|
|
holeToHoleMin = constraint.m_Value.Min();
|
|
|
|
}
|
|
|
|
|
|
|
|
aSizes.SetHoleToHole( holeToHoleMin );
|
2021-01-05 00:03:14 +00:00
|
|
|
|
2020-10-08 22:01:09 +00:00
|
|
|
aSizes.ClearLayerPairs();
|
|
|
|
|
|
|
|
return true;
|
2017-01-25 09:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-21 22:35:22 +00:00
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::matchDpSuffix( const wxString& aNetName, wxString& aComplementNet,
|
|
|
|
wxString& aBaseDpName )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if( aNetName.EndsWith( "+" ) )
|
|
|
|
{
|
|
|
|
aComplementNet = "-";
|
|
|
|
rv = 1;
|
|
|
|
}
|
2017-06-30 09:15:52 +00:00
|
|
|
else if( aNetName.EndsWith( "P" ) )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2017-06-30 09:15:52 +00:00
|
|
|
aComplementNet = "N";
|
2016-08-15 15:16:47 +00:00
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
else if( aNetName.EndsWith( "-" ) )
|
|
|
|
{
|
|
|
|
aComplementNet = "+";
|
|
|
|
rv = -1;
|
|
|
|
}
|
2017-06-30 09:15:52 +00:00
|
|
|
else if( aNetName.EndsWith( "N" ) )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2017-06-30 09:15:52 +00:00
|
|
|
aComplementNet = "P";
|
|
|
|
rv = -1;
|
|
|
|
}
|
2017-06-30 14:03:01 +00:00
|
|
|
// Match P followed by 2 digits
|
2017-06-30 09:15:52 +00:00
|
|
|
else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
|
|
|
|
{
|
|
|
|
aComplementNet = "N" + aNetName.Right( 2 );
|
|
|
|
rv = 1;
|
|
|
|
}
|
2017-06-30 14:03:01 +00:00
|
|
|
// Match P followed by 1 digit
|
2017-06-30 09:15:52 +00:00
|
|
|
else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
|
|
|
|
{
|
|
|
|
aComplementNet = "N" + aNetName.Right( 1 );
|
|
|
|
rv = 1;
|
|
|
|
}
|
2017-06-30 14:03:01 +00:00
|
|
|
// Match N followed by 2 digits
|
2017-06-30 09:15:52 +00:00
|
|
|
else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
|
|
|
|
{
|
|
|
|
aComplementNet = "P" + aNetName.Right( 2 );
|
|
|
|
rv = -1;
|
|
|
|
}
|
2017-06-30 14:03:01 +00:00
|
|
|
// Match N followed by 1 digit
|
2017-06-30 09:15:52 +00:00
|
|
|
else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
|
|
|
|
{
|
|
|
|
aComplementNet = "P" + aNetName.Right( 1 );
|
2016-08-15 15:16:47 +00:00
|
|
|
rv = -1;
|
|
|
|
}
|
|
|
|
if( rv != 0 )
|
|
|
|
{
|
|
|
|
aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
|
|
|
|
aComplementNet = aBaseDpName + aComplementNet;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::DpCoupledNet( int aNet )
|
|
|
|
{
|
|
|
|
wxString refName = m_board->FindNet( aNet )->GetNetname();
|
|
|
|
wxString dummy, coupledNetName;
|
|
|
|
|
|
|
|
if( matchDpSuffix( refName, coupledNetName, dummy ) )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
|
|
|
|
|
|
|
|
if( !net )
|
|
|
|
return -1;
|
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
return net->GetNetCode();
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-19 00:50:52 +00:00
|
|
|
wxString PNS_PCBNEW_RULE_RESOLVER::NetName( int aNet )
|
|
|
|
{
|
|
|
|
return m_board->FindNet( aNet )->GetNetname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::DpNetPolarity( int aNet )
|
|
|
|
{
|
|
|
|
wxString refName = m_board->FindNet( aNet )->GetNetname();
|
|
|
|
wxString dummy1, dummy2;
|
|
|
|
|
|
|
|
return matchDpSuffix( refName, dummy1, dummy2 );
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2020-10-08 22:01:09 +00:00
|
|
|
bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( const PNS::ITEM* aItem, int& aNetP, int& aNetN )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-10-17 12:52:18 +00:00
|
|
|
if( !aItem || !aItem->Parent() || !aItem->Parent()->IsConnected() )
|
2016-08-15 15:16:47 +00:00
|
|
|
return false;
|
|
|
|
|
2020-10-17 12:52:18 +00:00
|
|
|
BOARD_CONNECTED_ITEM* cItem = static_cast<BOARD_CONNECTED_ITEM*>( aItem->Parent() );
|
|
|
|
NETINFO_ITEM* netInfo = cItem->GetNet();
|
|
|
|
|
|
|
|
if( !netInfo )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxString netNameP = netInfo->GetNetname();
|
2016-08-15 15:16:47 +00:00
|
|
|
wxString netNameN, netNameCoupled, netNameBase;
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
if( r == 0 )
|
2020-10-17 12:52:18 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
return false;
|
2020-10-17 12:52:18 +00:00
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
else if( r == 1 )
|
|
|
|
{
|
|
|
|
netNameN = netNameCoupled;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
netNameN = netNameP;
|
|
|
|
netNameP = netNameCoupled;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:54 +00:00
|
|
|
// wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
|
|
|
|
NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
|
|
|
|
|
2016-08-15 15:16:54 +00:00
|
|
|
//wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
if( !netInfoP || !netInfoN )
|
|
|
|
return false;
|
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
aNetP = netInfoP->GetNetCode();
|
|
|
|
aNetN = netInfoN->GetNetCode();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class PNS_PCBNEW_DEBUG_DECORATOR: public PNS::DEBUG_DECORATOR
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-12-02 18:42:37 +00:00
|
|
|
PNS_PCBNEW_DEBUG_DECORATOR( KIGFX::VIEW* aView = NULL ) :
|
|
|
|
PNS::DEBUG_DECORATOR(),
|
|
|
|
m_view( NULL ),
|
|
|
|
m_items( NULL )
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
SetView( aView );
|
2016-08-15 15:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~PNS_PCBNEW_DEBUG_DECORATOR()
|
|
|
|
{
|
|
|
|
Clear();
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_items;
|
2016-08-15 15:16:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
void SetView( KIGFX::VIEW* aView )
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
delete m_items;
|
|
|
|
m_items = NULL;
|
|
|
|
m_view = aView;
|
2016-08-15 15:16:53 +00:00
|
|
|
|
|
|
|
if( m_view == NULL )
|
2016-08-15 15:16:48 +00:00
|
|
|
return;
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
m_items = new KIGFX::VIEW_GROUP( m_view );
|
2018-08-28 21:57:31 +00:00
|
|
|
m_items->SetLayer( LAYER_SELECT_OVERLAY ) ;
|
2016-08-15 15:16:48 +00:00
|
|
|
m_view->Add( m_items );
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:59:16 +00:00
|
|
|
virtual void AddPoint( VECTOR2I aP, int aColor, int aSize, const std::string aName ) override
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN l;
|
|
|
|
|
2020-10-18 20:59:16 +00:00
|
|
|
l.Append( aP - VECTOR2I( -aSize, -aSize ) );
|
|
|
|
l.Append( aP + VECTOR2I( -aSize, -aSize ) );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
AddLine( l, aColor, 10000 );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
|
|
|
l.Clear();
|
2020-10-18 20:59:16 +00:00
|
|
|
l.Append( aP - VECTOR2I( aSize, -aSize ) );
|
|
|
|
l.Append( aP + VECTOR2I( aSize, -aSize ) );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
|
|
|
AddLine( l, aColor, 10000 );
|
|
|
|
}
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
void AddBox( BOX2I aB, int aColor, const std::string aName = "" ) override
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN l;
|
|
|
|
|
|
|
|
VECTOR2I o = aB.GetOrigin();
|
|
|
|
VECTOR2I s = aB.GetSize();
|
|
|
|
|
|
|
|
l.Append( o );
|
|
|
|
l.Append( o.x + s.x, o.y );
|
|
|
|
l.Append( o.x + s.x, o.y + s.y );
|
|
|
|
l.Append( o.x, o.y + s.y );
|
|
|
|
l.Append( o );
|
|
|
|
|
|
|
|
AddLine( l, aColor, 10000 );
|
|
|
|
}
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
void AddSegment( SEG aS, int aColor, const std::string aName = "" ) override
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN l;
|
|
|
|
|
|
|
|
l.Append( aS.A );
|
|
|
|
l.Append( aS.B );
|
|
|
|
|
|
|
|
AddLine( l, aColor, 10000 );
|
|
|
|
}
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
void AddDirections( VECTOR2D aP, int aMask, int aColor,
|
|
|
|
const std::string aName = "" ) override
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
BOX2I b( aP - VECTOR2I( 10000, 10000 ), VECTOR2I( 20000, 20000 ) );
|
|
|
|
|
|
|
|
AddBox( b, aColor );
|
|
|
|
for( int i = 0; i < 8; i++ )
|
|
|
|
{
|
|
|
|
if( ( 1 << i ) & aMask )
|
|
|
|
{
|
|
|
|
VECTOR2I v = DIRECTION_45( ( DIRECTION_45::Directions ) i ).ToVector() * 100000;
|
|
|
|
AddSegment( SEG( aP, aP + v ), aColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
void AddLine( const SHAPE_LINE_CHAIN& aLine, int aType, int aWidth,
|
|
|
|
const std::string aName = "" ) override
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
2020-07-03 23:33:36 +00:00
|
|
|
if( !m_view )
|
|
|
|
return;
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_view );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
|
|
|
pitem->Line( aLine, aWidth, aType );
|
|
|
|
m_items->Add( pitem ); // Should not be needed, as m_items has been passed as a parent group in alloc;
|
2016-12-09 11:04:32 +00:00
|
|
|
m_view->Update( m_items );
|
2016-08-15 15:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() override
|
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
if( m_view && m_items )
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
m_items->FreeItems();
|
2016-12-09 11:04:32 +00:00
|
|
|
m_view->Update( m_items );
|
2016-08-15 15:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
KIGFX::VIEW* m_view;
|
|
|
|
KIGFX::VIEW_GROUP* m_items;
|
|
|
|
};
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
PNS::DEBUG_DECORATOR* PNS_KICAD_IFACE_BASE::GetDebugDecorator()
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
return m_debugDecorator;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
PNS_KICAD_IFACE_BASE::PNS_KICAD_IFACE_BASE()
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
m_ruleResolver = nullptr;
|
2016-08-15 15:16:48 +00:00
|
|
|
m_board = nullptr;
|
2020-04-16 22:29:28 +00:00
|
|
|
m_world = nullptr;
|
2019-12-30 14:26:33 +00:00
|
|
|
m_debugDecorator = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PNS_KICAD_IFACE::PNS_KICAD_IFACE()
|
|
|
|
{
|
2017-10-31 11:03:58 +00:00
|
|
|
m_tool = nullptr;
|
2016-08-15 15:16:48 +00:00
|
|
|
m_view = nullptr;
|
2016-08-15 15:16:47 +00:00
|
|
|
m_previewItems = nullptr;
|
2017-01-31 20:35:52 +00:00
|
|
|
m_dispOptions = nullptr;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
PNS_KICAD_IFACE_BASE::~PNS_KICAD_IFACE_BASE()
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2019-12-30 14:26:33 +00:00
|
|
|
}
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
|
|
|
|
PNS_KICAD_IFACE::~PNS_KICAD_IFACE()
|
|
|
|
{
|
2020-04-16 22:29:28 +00:00
|
|
|
delete m_ruleResolver;
|
|
|
|
delete m_debugDecorator;
|
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
if( m_previewItems )
|
2016-08-17 13:09:48 +00:00
|
|
|
{
|
|
|
|
m_previewItems->FreeItems();
|
|
|
|
delete m_previewItems;
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( PAD* aPad )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2020-06-27 21:44:56 +00:00
|
|
|
// ignore non-copper pads except for those with holes
|
2020-10-05 13:55:52 +00:00
|
|
|
if( ( aPad->GetLayerSet() & LSET::AllCuMask() ).none() && aPad->GetDrillSize().x == 0 )
|
2016-08-15 15:16:47 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch( aPad->GetAttribute() )
|
|
|
|
{
|
2020-09-30 15:38:35 +00:00
|
|
|
case PAD_ATTRIB_PTH:
|
2020-10-05 19:54:12 +00:00
|
|
|
case PAD_ATTRIB_NPTH:
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_ATTRIB_CONN:
|
2020-06-27 21:44:56 +00:00
|
|
|
case PAD_ATTRIB_SMD:
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
LSET lmsk = aPad->GetLayerSet();
|
|
|
|
bool is_copper = false;
|
|
|
|
|
|
|
|
for( int i = 0; i < MAX_CU_LAYERS; i++ )
|
|
|
|
{
|
|
|
|
if( lmsk[i] )
|
|
|
|
{
|
|
|
|
is_copper = true;
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2020-09-30 15:38:35 +00:00
|
|
|
if( aPad->GetAttribute() != PAD_ATTRIB_NPTH )
|
2016-08-29 17:31:13 +00:00
|
|
|
layers = LAYER_RANGE( i );
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 19:54:12 +00:00
|
|
|
if( !is_copper )
|
2016-08-15 15:16:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "unsupported pad type 0x%x", aPad->GetAttribute() );
|
2016-08-15 15:16:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2020-10-05 13:55:52 +00:00
|
|
|
if( aPad->GetDrillSize().x > 0 )
|
|
|
|
{
|
|
|
|
SHAPE_SEGMENT* slot = (SHAPE_SEGMENT*) aPad->GetEffectiveHoleShape()->Clone();
|
|
|
|
|
|
|
|
if( aPad->GetAttribute() != PAD_ATTRIB_NPTH )
|
|
|
|
{
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
slot->SetWidth( slot->GetWidth() + bds.GetHolePlatingThickness() * 2 );
|
|
|
|
}
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
solid->SetHole( slot );
|
2020-10-05 13:55:52 +00:00
|
|
|
}
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2020-09-30 15:38:35 +00:00
|
|
|
if( aPad->GetAttribute() == PAD_ATTRIB_NPTH )
|
2020-08-21 04:49:40 +00:00
|
|
|
solid->SetRoutable( false );
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
solid->SetLayers( layers );
|
|
|
|
solid->SetNet( aPad->GetNetCode() );
|
|
|
|
solid->SetParent( aPad );
|
2019-10-31 13:00:01 +00:00
|
|
|
solid->SetPadToDie( aPad->GetPadToDieLength() );
|
2020-12-29 06:06:46 +00:00
|
|
|
solid->SetOrientation( aPad->GetOrientation() );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
wxPoint wx_c = aPad->ShapePos();
|
|
|
|
wxPoint offset = aPad->GetOffset();
|
|
|
|
|
|
|
|
VECTOR2I c( wx_c.x, wx_c.y );
|
|
|
|
|
|
|
|
RotatePoint( &offset, aPad->GetOrientation() );
|
|
|
|
|
|
|
|
solid->SetPos( VECTOR2I( c.x - offset.x, c.y - offset.y ) );
|
2016-12-09 11:04:32 +00:00
|
|
|
solid->SetOffset( VECTOR2I( offset.x, offset.y ) );
|
2020-10-07 13:17:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
auto shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
|
|
|
|
|
|
|
|
if( shapes && shapes->Size() == 1 )
|
|
|
|
{
|
2020-10-19 21:34:24 +00:00
|
|
|
solid->SetShape( shapes->Shapes()[0]->Clone() );
|
2020-10-07 13:17:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Fixme (but not urgent). For complex pad shapes, we pass a single simple polygon to the
|
|
|
|
// router, otherwise it won't know how to correctly build walkaround 'hulls' for the pad
|
|
|
|
// primitives - it can recognize only simple shapes, but not COMPOUNDs made of multiple shapes.
|
|
|
|
// The proper way to fix this would be to implement SHAPE_COMPOUND::ConvertToSimplePolygon(),
|
2020-11-12 22:30:02 +00:00
|
|
|
// but the complexity of pad polygonization code (see PAD::GetEffectivePolygon), including approximation
|
2020-10-07 13:17:04 +00:00
|
|
|
// error handling makes me slightly scared to do it right now.
|
|
|
|
|
|
|
|
const std::shared_ptr<SHAPE_POLY_SET>& outline = aPad->GetEffectivePolygon();
|
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
|
|
|
|
|
|
|
for( auto iter = outline->CIterate( 0 ); iter; iter++ )
|
|
|
|
shape->Append( *iter );
|
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
return solid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( TRACK* aTrack )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
auto segment = std::make_unique<PNS::SEGMENT>( SEG( aTrack->GetStart(), aTrack->GetEnd() ),
|
|
|
|
aTrack->GetNetCode() );
|
2016-08-30 15:28:35 +00:00
|
|
|
|
|
|
|
segment->SetWidth( aTrack->GetWidth() );
|
|
|
|
segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) );
|
|
|
|
segment->SetParent( aTrack );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
if( aTrack->IsLocked() )
|
2016-08-30 15:28:35 +00:00
|
|
|
segment->Mark( PNS::MK_LOCKED );
|
|
|
|
|
|
|
|
return segment;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
std::unique_ptr<PNS::ARC> PNS_KICAD_IFACE_BASE::syncArc( ARC* aArc )
|
2019-05-17 00:13:21 +00:00
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
auto arc = std::make_unique<PNS::ARC>( SHAPE_ARC( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(),
|
|
|
|
aArc->GetWidth() ),
|
|
|
|
aArc->GetNetCode() );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
arc->SetLayers( LAYER_RANGE( aArc->GetLayer() ) );
|
|
|
|
arc->SetParent( aArc );
|
|
|
|
|
|
|
|
if( aArc->IsLocked() )
|
|
|
|
arc->Mark( PNS::MK_LOCKED );
|
|
|
|
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-16 19:36:58 +00:00
|
|
|
std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE_BASE::syncVia( VIA* aVia )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID top, bottom;
|
2016-08-15 15:16:47 +00:00
|
|
|
aVia->LayerPair( &top, &bottom );
|
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
auto via = std::make_unique<PNS::VIA>( aVia->GetPosition(),
|
|
|
|
LAYER_RANGE( aVia->TopLayer(), aVia->BottomLayer() ),
|
|
|
|
aVia->GetWidth(),
|
|
|
|
aVia->GetDrillValue(),
|
|
|
|
aVia->GetNetCode(),
|
|
|
|
aVia->GetViaType() );
|
2016-08-30 15:28:35 +00:00
|
|
|
|
2020-08-16 19:36:58 +00:00
|
|
|
via->SetParent( aVia );
|
2020-07-27 19:41:50 +00:00
|
|
|
|
2020-08-16 19:36:58 +00:00
|
|
|
if( aVia->IsLocked() )
|
|
|
|
via->Mark( PNS::MK_LOCKED );
|
2020-07-27 19:41:50 +00:00
|
|
|
|
2020-12-20 21:29:43 +00:00
|
|
|
via->SetIsFree( aVia->GetIsFree() );
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
via->SetHole( SHAPE_CIRCLE( aVia->GetPosition(),
|
|
|
|
aVia->GetDrill() / 2 + bds.GetHolePlatingThickness() ) );
|
|
|
|
|
2020-12-09 23:12:44 +00:00
|
|
|
return via;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 09:24:57 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
bool PNS_KICAD_IFACE_BASE::syncZone( PNS::NODE* aWorld, ZONE* aZone, SHAPE_POLY_SET* aBoardOutline )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
2021-01-30 00:32:48 +00:00
|
|
|
SHAPE_POLY_SET* poly;
|
2018-02-03 09:39:46 +00:00
|
|
|
|
2021-01-01 23:17:15 +00:00
|
|
|
if( !aZone->GetIsRuleArea() && aZone->GetZoneName().IsEmpty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Required by expression function insideArea()
|
|
|
|
aZone->CacheBoundingBox();
|
|
|
|
|
|
|
|
// TODO handle aZone->GetDoNotAllowVias()
|
|
|
|
// TODO handle rules which disallow tracks & vias
|
2020-09-21 23:32:07 +00:00
|
|
|
if( !aZone->GetIsRuleArea() || !aZone->GetDoNotAllowTracks() )
|
2018-02-03 09:39:46 +00:00
|
|
|
return false;
|
|
|
|
|
2020-10-20 10:33:51 +00:00
|
|
|
LSET layers = aZone->GetLayerSet();
|
|
|
|
EDA_UNITS units = EDA_UNITS::MILLIMETRES; // TODO: get real units
|
2018-02-03 09:39:46 +00:00
|
|
|
|
2021-01-30 00:32:48 +00:00
|
|
|
poly = aZone->Outline();
|
|
|
|
poly->CacheTriangulation( false );
|
2018-02-03 09:39:46 +00:00
|
|
|
|
2021-01-30 00:32:48 +00:00
|
|
|
if( !poly->IsTriangulationUpToDate() )
|
|
|
|
{
|
|
|
|
KIDIALOG dlg( nullptr, wxString::Format( _( "%s is malformed." ),
|
|
|
|
aZone->GetSelectMenuText( units ) ),
|
|
|
|
KIDIALOG::KD_WARNING );
|
|
|
|
dlg.ShowDetailedText( wxString::Format( _( "This zone cannot be handled by the track "
|
|
|
|
"layout tool.\n"
|
|
|
|
"Please verify it is not a "
|
|
|
|
"self-intersecting polygon." ) ) );
|
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
dlg.ShowModal();
|
2020-08-12 18:42:40 +00:00
|
|
|
|
2021-01-30 00:32:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-12 18:42:40 +00:00
|
|
|
|
2021-01-30 00:32:48 +00:00
|
|
|
for( int layer = F_Cu; layer <= B_Cu; layer++ )
|
|
|
|
{
|
|
|
|
if( !layers[ layer ] )
|
|
|
|
continue;
|
2020-08-12 18:42:40 +00:00
|
|
|
|
2021-01-30 00:32:48 +00:00
|
|
|
for( int outline = 0; outline < poly->OutlineCount(); outline++ )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
2021-01-30 00:32:48 +00:00
|
|
|
const SHAPE_POLY_SET::TRIANGULATED_POLYGON* tri = poly->TriangulatedPolygon( outline );
|
2018-02-03 09:39:46 +00:00
|
|
|
|
2018-09-12 20:39:41 +00:00
|
|
|
for( size_t i = 0; i < tri->GetTriangleCount(); i++)
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
|
|
|
VECTOR2I a, b, c;
|
|
|
|
tri->GetTriangle( i, a, b, c );
|
2020-10-20 10:33:51 +00:00
|
|
|
SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
|
2018-02-03 09:39:46 +00:00
|
|
|
|
|
|
|
triShape->Append( a );
|
|
|
|
triShape->Append( b );
|
|
|
|
triShape->Append( c );
|
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
|
2018-02-03 09:39:46 +00:00
|
|
|
|
|
|
|
solid->SetLayer( layer );
|
2019-07-04 19:57:16 +00:00
|
|
|
solid->SetNet( -1 );
|
2018-02-03 09:39:46 +00:00
|
|
|
solid->SetParent( aZone );
|
|
|
|
solid->SetShape( triShape );
|
|
|
|
solid->SetRoutable( false );
|
|
|
|
|
|
|
|
aWorld->Add( std::move( solid ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-27 13:51:37 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
bool PNS_KICAD_IFACE_BASE::syncTextItem( PNS::NODE* aWorld, EDA_TEXT* aText, PCB_LAYER_ID aLayer )
|
2018-08-27 13:51:37 +00:00
|
|
|
{
|
|
|
|
if( !IsCopperLayer( aLayer ) )
|
|
|
|
return false;
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int textWidth = aText->GetEffectiveTextPenWidth();
|
2020-11-21 11:26:57 +00:00
|
|
|
std::vector<wxPoint> textShape = aText->TransformToSegmentList();
|
2018-08-27 13:51:37 +00:00
|
|
|
|
|
|
|
if( textShape.size() < 2 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( size_t jj = 0; jj < textShape.size(); jj += 2 )
|
|
|
|
{
|
|
|
|
VECTOR2I start( textShape[jj] );
|
|
|
|
VECTOR2I end( textShape[jj+1] );
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
|
2018-08-27 13:51:37 +00:00
|
|
|
|
|
|
|
solid->SetLayer( aLayer );
|
|
|
|
solid->SetNet( -1 );
|
2020-10-17 12:52:18 +00:00
|
|
|
solid->SetParent( dynamic_cast<BOARD_ITEM*>( aText ) );
|
2018-08-27 13:51:37 +00:00
|
|
|
solid->SetShape( new SHAPE_SEGMENT( start, end, textWidth ) );
|
|
|
|
solid->SetRoutable( false );
|
|
|
|
|
|
|
|
aWorld->Add( std::move( solid ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* A coarser (but faster) method:
|
|
|
|
*
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
|
|
|
|
|
|
|
aText->TransformBoundingBoxWithClearanceToPolygon( &outline, 0 );
|
|
|
|
|
|
|
|
for( auto iter = outline.CIterate( 0 ); iter; iter++ )
|
|
|
|
shape->Append( *iter );
|
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
|
|
|
|
solid->SetLayer( aLayer );
|
|
|
|
solid->SetNet( -1 );
|
|
|
|
solid->SetParent( nullptr );
|
|
|
|
solid->SetRoutable( false );
|
|
|
|
aWorld->Add( std::move( solid ) );
|
|
|
|
return true;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
bool PNS_KICAD_IFACE_BASE::syncGraphicalItem( PNS::NODE* aWorld, PCB_SHAPE* aItem )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
2020-11-20 21:22:27 +00:00
|
|
|
if( aItem->GetLayer() == Edge_Cuts
|
|
|
|
|| aItem->GetLayer() == Margin
|
|
|
|
|| IsCopperLayer( aItem->GetLayer() ) )
|
|
|
|
{
|
|
|
|
// TODO: where do we handle filled polygons on copper layers?
|
|
|
|
if( aItem->GetShape() == S_POLYGON && aItem->IsFilled() )
|
|
|
|
return false;
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
for( SHAPE* shape : aItem->MakeEffectiveShapes() )
|
|
|
|
{
|
|
|
|
std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
if( aItem->GetLayer() == Edge_Cuts || aItem->GetLayer() == Margin )
|
|
|
|
solid->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
|
|
|
|
else
|
|
|
|
solid->SetLayer( aItem->GetLayer() );
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2020-11-26 17:42:02 +00:00
|
|
|
if( aItem->GetLayer() == Edge_Cuts )
|
|
|
|
{
|
|
|
|
switch( shape->Type() )
|
|
|
|
{
|
|
|
|
case SH_SEGMENT: static_cast<SHAPE_SEGMENT*>( shape )->SetWidth( 0 ); break;
|
|
|
|
case SH_ARC: static_cast<SHAPE_ARC*>( shape )->SetWidth( 0 ); break;
|
|
|
|
case SH_LINE_CHAIN: static_cast<SHAPE_LINE_CHAIN*>( shape )->SetWidth( 0 ); break;
|
|
|
|
default: /* remaining shapes don't have width */ break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
solid->SetNet( -1 );
|
|
|
|
solid->SetParent( aItem );
|
|
|
|
solid->SetShape( shape );
|
|
|
|
solid->SetRoutable( false );
|
2018-08-27 13:51:37 +00:00
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
aWorld->Add( std::move( solid ) );
|
|
|
|
}
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
return true;
|
2018-02-04 12:09:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 21:22:27 +00:00
|
|
|
return false;
|
2018-02-03 09:39:46 +00:00
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2019-08-15 07:21:48 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
void PNS_KICAD_IFACE_BASE::SetBoard( BOARD* aBoard )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
m_board = aBoard;
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "m_board = %p", m_board );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-05 19:54:12 +00:00
|
|
|
bool PNS_KICAD_IFACE::IsAnyLayerVisible( const LAYER_RANGE& aLayer ) const
|
2019-08-15 07:21:48 +00:00
|
|
|
{
|
|
|
|
if( !m_view )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( int i = aLayer.Start(); i <= aLayer.End(); i++ )
|
|
|
|
if( m_view->IsLayerVisible( i ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
bool PNS_KICAD_IFACE::IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const
|
2020-08-16 19:36:58 +00:00
|
|
|
{
|
2020-08-25 16:39:56 +00:00
|
|
|
/// Default is all layers
|
|
|
|
if( aLayer < 0 )
|
|
|
|
return true;
|
|
|
|
|
2020-10-17 12:52:18 +00:00
|
|
|
if( aItem->Parent() )
|
2020-08-16 19:36:58 +00:00
|
|
|
{
|
2020-10-17 12:52:18 +00:00
|
|
|
switch( aItem->Parent()->Type() )
|
|
|
|
{
|
|
|
|
case PCB_VIA_T:
|
|
|
|
{
|
|
|
|
const VIA* via = static_cast<const VIA*>( aItem->Parent() );
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
return via->FlashLayer( static_cast<PCB_LAYER_ID>( aLayer ) );
|
2020-10-17 12:52:18 +00:00
|
|
|
}
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2020-10-17 12:52:18 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
const PAD* pad = static_cast<const PAD*>( aItem->Parent() );
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
return pad->FlashLayer( static_cast<PCB_LAYER_ID>( aLayer ) );
|
2020-10-17 12:52:18 +00:00
|
|
|
}
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2020-10-17 12:52:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-08-16 19:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aItem->Layers().Overlaps( aLayer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-05 19:54:12 +00:00
|
|
|
bool PNS_KICAD_IFACE::IsItemVisible( const PNS::ITEM* aItem ) const
|
2019-10-10 13:33:21 +00:00
|
|
|
{
|
2020-10-17 12:52:18 +00:00
|
|
|
// by default, all items are visible (new ones created by the router have parent == NULL
|
|
|
|
// as they have not been committed yet to the BOARD)
|
2019-10-15 13:30:56 +00:00
|
|
|
if( !m_view || !aItem->Parent() )
|
2020-02-29 19:41:31 +00:00
|
|
|
return true;
|
2019-10-10 13:33:21 +00:00
|
|
|
|
2020-11-08 17:16:00 +00:00
|
|
|
BOARD_ITEM* item = aItem->Parent();
|
|
|
|
bool isOnVisibleLayer = true;
|
|
|
|
RENDER_SETTINGS* settings = m_view->GetPainter()->GetSettings();
|
2019-10-15 13:30:56 +00:00
|
|
|
|
2020-11-08 17:16:00 +00:00
|
|
|
if( settings->GetHighContrast() )
|
|
|
|
isOnVisibleLayer = item->IsOnLayer( settings->GetPrimaryHighContrastLayer() );
|
2019-10-10 13:33:21 +00:00
|
|
|
|
2019-10-15 13:30:56 +00:00
|
|
|
if( m_view->IsVisible( item ) && isOnVisibleLayer
|
2019-10-10 13:33:21 +00:00
|
|
|
&& item->ViewGetLOD( item->GetLayer(), m_view ) < m_view->GetScale() )
|
2020-11-08 17:16:00 +00:00
|
|
|
{
|
2019-10-10 13:33:21 +00:00
|
|
|
return true;
|
2020-11-08 17:16:00 +00:00
|
|
|
}
|
2019-10-10 13:33:21 +00:00
|
|
|
|
2019-12-07 17:47:16 +00:00
|
|
|
// Items hidden in the router are not hidden on the board
|
|
|
|
if( m_hiddenItems.find( item ) != m_hiddenItems.end() )
|
|
|
|
return true;
|
|
|
|
|
2019-10-10 13:33:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
void PNS_KICAD_IFACE_BASE::SyncWorld( PNS::NODE *aWorld )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
if( !m_board )
|
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "No board attached, aborting sync." );
|
2016-08-15 15:16:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:58:22 +00:00
|
|
|
int worstClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
|
|
|
|
|
|
|
|
m_world = aWorld;
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
for( BOARD_ITEM* gitem : m_board->Drawings() )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if ( gitem->Type() == PCB_SHAPE_T )
|
2018-02-09 12:00:57 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
syncGraphicalItem( aWorld, static_cast<PCB_SHAPE*>( gitem ) );
|
2018-02-09 12:00:57 +00:00
|
|
|
}
|
2018-08-27 13:51:37 +00:00
|
|
|
else if( gitem->Type() == PCB_TEXT_T )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
syncTextItem( aWorld, static_cast<PCB_TEXT*>( gitem ), gitem->GetLayer() );
|
2018-08-27 13:51:37 +00:00
|
|
|
}
|
2018-02-03 09:39:46 +00:00
|
|
|
}
|
|
|
|
|
2020-10-10 22:09:00 +00:00
|
|
|
SHAPE_POLY_SET buffer;
|
|
|
|
SHAPE_POLY_SET* boardOutline = nullptr;
|
|
|
|
|
|
|
|
if( m_board->GetBoardPolygonOutlines( buffer ) )
|
|
|
|
boardOutline = &buffer;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
2020-10-10 22:09:00 +00:00
|
|
|
syncZone( aWorld, zone, boardOutline );
|
2018-02-03 09:39:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-10-05 19:54:12 +00:00
|
|
|
if( std::unique_ptr<PNS::SOLID> solid = syncPad( pad ) )
|
2016-08-30 15:28:35 +00:00
|
|
|
aWorld->Add( std::move( solid ) );
|
2017-12-18 17:51:44 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
worstClearance = std::max( worstClearance, pad->GetLocalClearance() );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
2018-08-27 13:51:37 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
syncTextItem( aWorld, &footprint->Reference(), footprint->Reference().GetLayer() );
|
|
|
|
syncTextItem( aWorld, &footprint->Value(), footprint->Value().GetLayer() );
|
2018-08-27 13:51:37 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FP_ZONE* zone : footprint->Zones() )
|
2020-10-10 22:09:00 +00:00
|
|
|
syncZone( aWorld, zone, boardOutline );
|
2019-10-28 09:15:03 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
if( footprint->IsNetTie() )
|
2018-11-03 17:31:07 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( BOARD_ITEM* mgitem : footprint->GraphicalItems() )
|
2018-08-27 13:51:37 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( mgitem->Type() == PCB_FP_SHAPE_T )
|
2018-08-27 13:51:37 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
syncGraphicalItem( aWorld, static_cast<PCB_SHAPE*>( mgitem ) );
|
2018-08-27 13:51:37 +00:00
|
|
|
}
|
2020-10-04 14:19:33 +00:00
|
|
|
else if( mgitem->Type() == PCB_FP_TEXT_T )
|
2018-08-27 13:51:37 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
syncTextItem( aWorld, static_cast<FP_TEXT*>( mgitem ), mgitem->GetLayer() );
|
2018-08-27 13:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
for( TRACK* t : m_board->Tracks() )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
KICAD_T type = t->Type();
|
|
|
|
|
2019-01-12 15:24:00 +00:00
|
|
|
if( type == PCB_TRACE_T )
|
|
|
|
{
|
|
|
|
if( auto segment = syncTrack( t ) )
|
2016-06-21 15:06:28 +00:00
|
|
|
aWorld->Add( std::move( segment ) );
|
2019-01-12 15:24:00 +00:00
|
|
|
}
|
2019-05-17 00:13:21 +00:00
|
|
|
else if( type == PCB_ARC_T )
|
|
|
|
{
|
|
|
|
if( auto arc = syncArc( static_cast<ARC*>( t ) ) )
|
|
|
|
aWorld->Add( std::move( arc ) );
|
|
|
|
}
|
2019-01-12 15:24:00 +00:00
|
|
|
else if( type == PCB_VIA_T )
|
|
|
|
{
|
2020-08-16 19:36:58 +00:00
|
|
|
if( auto via = syncVia( static_cast<VIA*>( t ) ) )
|
2016-08-30 15:28:35 +00:00
|
|
|
aWorld->Add( std::move( via ) );
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 17:17:11 +00:00
|
|
|
// NB: if this were ever to become a long-lived object we would need to dirty its
|
|
|
|
// clearance cache here....
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_ruleResolver;
|
2020-04-16 22:29:28 +00:00
|
|
|
m_ruleResolver = new PNS_PCBNEW_RULE_RESOLVER( m_board, this );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
aWorld->SetRuleResolver( m_ruleResolver );
|
2021-01-01 00:29:05 +00:00
|
|
|
aWorld->SetMaxClearance( 4 * worstClearance );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
void PNS_KICAD_IFACE::EraseView()
|
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
for( auto item : m_hiddenItems )
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->SetVisible( item, true );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
m_hiddenItems.clear();
|
|
|
|
|
|
|
|
if( m_previewItems )
|
|
|
|
{
|
|
|
|
m_previewItems->FreeItems();
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->Update( m_previewItems );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( m_debugDecorator )
|
2016-08-15 15:16:48 +00:00
|
|
|
m_debugDecorator->Clear();
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
void PNS_KICAD_IFACE_BASE::SetDebugDecorator( PNS::DEBUG_DECORATOR *aDec )
|
|
|
|
{
|
|
|
|
m_debugDecorator = aDec;
|
|
|
|
}
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2021-01-03 21:14:44 +00:00
|
|
|
void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-12-02 17:58:12 +00:00
|
|
|
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
if( aClearance >= 0 )
|
2017-01-25 09:33:49 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
pitem->SetClearance( aClearance );
|
|
|
|
|
2019-11-07 14:23:09 +00:00
|
|
|
switch( m_dispOptions->m_ShowTrackClearanceMode )
|
2017-01-25 09:33:49 +00:00
|
|
|
{
|
2019-11-07 14:23:09 +00:00
|
|
|
case PCB_DISPLAY_OPTIONS::DO_NOT_SHOW_CLEARANCE:
|
|
|
|
pitem->ShowTrackClearance( false );
|
|
|
|
pitem->ShowViaClearance( false );
|
|
|
|
break;
|
|
|
|
case PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_ALWAYS:
|
|
|
|
case PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_NEW_AND_EDITED_TRACKS_AND_VIA_AREAS:
|
|
|
|
pitem->ShowTrackClearance( true );
|
|
|
|
pitem->ShowViaClearance( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS:
|
|
|
|
pitem->ShowTrackClearance( !aEdit );
|
|
|
|
pitem->ShowViaClearance( !aEdit );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_DISPLAY_OPTIONS::SHOW_CLEARANCE_NEW_TRACKS:
|
|
|
|
pitem->ShowTrackClearance( !aEdit );
|
|
|
|
pitem->ShowViaClearance( false );
|
|
|
|
break;
|
2017-01-25 09:33:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
m_previewItems->Add( pitem );
|
2016-12-09 11:04:32 +00:00
|
|
|
m_view->Update( m_previewItems );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2020-10-14 00:04:47 +00:00
|
|
|
void PNS_KICAD_IFACE::DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor )
|
|
|
|
{
|
|
|
|
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( nullptr, m_view );
|
|
|
|
pitem->Line( aRatline, 10000, aColor );
|
|
|
|
m_previewItems->Add( pitem );
|
|
|
|
m_view->Update( m_previewItems );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void PNS_KICAD_IFACE::HideItem( PNS::ITEM* aItem )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-10-17 12:52:18 +00:00
|
|
|
BOARD_ITEM* parent = aItem->Parent();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
if( parent )
|
|
|
|
{
|
2016-12-09 11:04:32 +00:00
|
|
|
if( m_view->IsVisible( parent ) )
|
2016-08-15 15:16:47 +00:00
|
|
|
m_hiddenItems.insert( parent );
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
m_view->SetVisible( parent, false );
|
2016-12-09 11:04:32 +00:00
|
|
|
m_view->Update( parent, KIGFX::APPEARANCE );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
void PNS_KICAD_IFACE_BASE::RemoveItem( PNS::ITEM* aItem )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2020-10-17 12:52:18 +00:00
|
|
|
BOARD_ITEM* parent = aItem->Parent();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2021-02-17 00:47:42 +00:00
|
|
|
if( aItem->OfKind( PNS::ITEM::SOLID_T ) )
|
2020-02-28 22:09:19 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( parent );
|
2020-10-17 12:52:18 +00:00
|
|
|
VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
|
2020-02-28 22:09:19 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_fpOffsets[ pad ].p_old = pos;
|
2020-02-28 22:09:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
if( parent )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
m_commit->Remove( parent );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2021-02-08 01:06:56 +00:00
|
|
|
void PNS_KICAD_IFACE_BASE::UpdateItem( PNS::ITEM* aItem )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PNS_KICAD_IFACE::UpdateItem( PNS::ITEM* aItem )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* board_item = aItem->Parent();
|
|
|
|
|
|
|
|
m_commit->Modify( board_item );
|
|
|
|
|
|
|
|
switch( aItem->Kind() )
|
|
|
|
{
|
|
|
|
case PNS::ITEM::ARC_T:
|
|
|
|
{
|
|
|
|
PNS::ARC* arc = static_cast<PNS::ARC*>( aItem );
|
|
|
|
ARC* arc_board = static_cast<ARC*>( board_item );
|
|
|
|
const SHAPE_ARC* arc_shape = static_cast<const SHAPE_ARC*>( arc->Shape() );
|
|
|
|
arc_board->SetStart( wxPoint( arc_shape->GetP0() ) );
|
|
|
|
arc_board->SetEnd( wxPoint( arc_shape->GetP1() ) );
|
|
|
|
arc_board->SetMid( wxPoint( arc_shape->GetArcMid() ) );
|
|
|
|
arc_board->SetWidth( arc->Width() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PNS::ITEM::SEGMENT_T:
|
|
|
|
{
|
|
|
|
PNS::SEGMENT* seg = static_cast<PNS::SEGMENT*>( aItem );
|
|
|
|
TRACK* track = static_cast<TRACK*>( board_item );
|
|
|
|
const SEG& s = seg->Seg();
|
|
|
|
track->SetStart( wxPoint( s.A.x, s.A.y ) );
|
|
|
|
track->SetEnd( wxPoint( s.B.x, s.B.y ) );
|
|
|
|
track->SetWidth( seg->Width() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PNS::ITEM::VIA_T:
|
|
|
|
{
|
|
|
|
VIA* via_board = static_cast<VIA*>( board_item );
|
|
|
|
PNS::VIA* via = static_cast<PNS::VIA*>( aItem );
|
|
|
|
via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
|
|
|
|
via_board->SetWidth( via->Diameter() );
|
|
|
|
via_board->SetDrill( via->Drill() );
|
|
|
|
via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
|
|
|
|
via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
|
|
|
|
via_board->SetIsFree( via->IsFree() );
|
|
|
|
via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
|
|
|
|
ToLAYER_ID( via->Layers().End() ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PNS::ITEM::SOLID_T:
|
|
|
|
{
|
|
|
|
PAD* pad = static_cast<PAD*>( aItem->Parent() );
|
|
|
|
VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
|
|
|
|
|
2021-02-17 00:47:42 +00:00
|
|
|
m_fpOffsets[ pad ].p_old = pad->GetPosition();
|
2021-02-08 01:06:56 +00:00
|
|
|
m_fpOffsets[ pad ].p_new = pos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
void PNS_KICAD_IFACE_BASE::AddItem( PNS::ITEM* aItem )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void PNS_KICAD_IFACE::AddItem( PNS::ITEM* aItem )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
BOARD_CONNECTED_ITEM* newBI = NULL;
|
|
|
|
|
|
|
|
switch( aItem->Kind() )
|
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
case PNS::ITEM::ARC_T:
|
|
|
|
{
|
|
|
|
auto arc = static_cast<PNS::ARC*>( aItem );
|
|
|
|
ARC* new_arc = new ARC( m_board, static_cast<const SHAPE_ARC*>( arc->Shape() ) );
|
|
|
|
new_arc->SetWidth( arc->Width() );
|
|
|
|
new_arc->SetLayer( ToLAYER_ID( arc->Layers().Start() ) );
|
|
|
|
new_arc->SetNetCode( std::max<int>( 0, arc->Net() ) );
|
|
|
|
newBI = new_arc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case PNS::ITEM::SEGMENT_T:
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS::SEGMENT* seg = static_cast<PNS::SEGMENT*>( aItem );
|
2016-08-15 15:16:47 +00:00
|
|
|
TRACK* track = new TRACK( m_board );
|
|
|
|
const SEG& s = seg->Seg();
|
|
|
|
track->SetStart( wxPoint( s.A.x, s.A.y ) );
|
|
|
|
track->SetEnd( wxPoint( s.B.x, s.B.y ) );
|
|
|
|
track->SetWidth( seg->Width() );
|
|
|
|
track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) );
|
|
|
|
track->SetNetCode( seg->Net() > 0 ? seg->Net() : 0 );
|
|
|
|
newBI = track;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case PNS::ITEM::VIA_T:
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
VIA* via_board = new VIA( m_board );
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS::VIA* via = static_cast<PNS::VIA*>( aItem );
|
2016-08-15 15:16:47 +00:00
|
|
|
via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
|
|
|
|
via_board->SetWidth( via->Diameter() );
|
|
|
|
via_board->SetDrill( via->Drill() );
|
|
|
|
via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
|
|
|
|
via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
|
2020-12-20 21:29:43 +00:00
|
|
|
via_board->SetIsFree( via->IsFree() );
|
2016-08-15 15:16:47 +00:00
|
|
|
via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
|
|
|
|
ToLAYER_ID( via->Layers().End() ) );
|
|
|
|
newBI = via_board;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-28 22:09:19 +00:00
|
|
|
case PNS::ITEM::SOLID_T:
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( aItem->Parent() );
|
2020-10-17 12:52:18 +00:00
|
|
|
VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
|
2020-02-28 22:09:19 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_fpOffsets[ pad ].p_new = pos;
|
2020-02-28 22:09:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( newBI )
|
|
|
|
{
|
2019-12-30 14:26:33 +00:00
|
|
|
//newBI->SetLocalRatsnestVisible( m_dispOptions->m_ShowGlobalRatsnest );
|
2016-08-15 15:16:47 +00:00
|
|
|
aItem->SetParent( newBI );
|
|
|
|
newBI->ClearFlags();
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
m_commit->Add( newBI );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
void PNS_KICAD_IFACE::Commit()
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::set<FOOTPRINT*> processedMods;
|
2020-02-28 22:09:19 +00:00
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
EraseView();
|
2020-02-28 22:09:19 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( auto fpOffset : m_fpOffsets )
|
2020-02-28 22:09:19 +00:00
|
|
|
{
|
2021-02-17 00:47:42 +00:00
|
|
|
VECTOR2I offset = fpOffset.second.p_new - fpOffset.second.p_old;
|
|
|
|
FOOTPRINT* footprint = fpOffset.first->GetParent();
|
2020-02-28 22:09:19 +00:00
|
|
|
|
2021-02-17 00:47:42 +00:00
|
|
|
VECTOR2I p_orig = footprint->GetPosition();
|
2020-02-28 22:09:19 +00:00
|
|
|
VECTOR2I p_new = p_orig + offset;
|
|
|
|
|
2021-02-17 00:47:42 +00:00
|
|
|
if( processedMods.find( footprint ) != processedMods.end() )
|
2020-02-28 22:09:19 +00:00
|
|
|
continue;
|
|
|
|
|
2021-02-17 00:47:42 +00:00
|
|
|
processedMods.insert( footprint );
|
|
|
|
m_commit->Modify( footprint );
|
|
|
|
footprint->SetPosition( wxPoint( p_new.x, p_new.y ) );
|
2020-02-28 22:09:19 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_fpOffsets.clear();
|
2020-02-28 22:09:19 +00:00
|
|
|
|
|
|
|
m_commit->Push( _( "Interactive Router" ) );
|
2019-12-05 13:43:55 +00:00
|
|
|
m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
void PNS_KICAD_IFACE::SetView( KIGFX::VIEW* aView )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "SetView %p", aView );
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
if( m_previewItems )
|
|
|
|
{
|
|
|
|
m_previewItems->FreeItems();
|
|
|
|
delete m_previewItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_view = aView;
|
|
|
|
m_previewItems = new KIGFX::VIEW_GROUP( m_view );
|
2018-08-28 21:57:31 +00:00
|
|
|
m_previewItems->SetLayer( LAYER_SELECT_OVERLAY ) ;
|
2020-03-29 16:42:24 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
if(m_view)
|
|
|
|
m_view->Add( m_previewItems );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_debugDecorator;
|
2019-12-30 14:26:33 +00:00
|
|
|
|
2021-02-25 16:18:13 +00:00
|
|
|
auto dec = new PNS_PCBNEW_DEBUG_DECORATOR();
|
2019-12-30 14:26:33 +00:00
|
|
|
m_debugDecorator = dec;
|
2020-07-03 23:33:36 +00:00
|
|
|
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_ShowRouterDebugGraphics )
|
|
|
|
dec->SetView( m_view );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
void PNS_KICAD_IFACE::UpdateNet( int aNetCode )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "Update-net %d", aNetCode );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
}
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2019-12-30 14:26:33 +00:00
|
|
|
PNS::RULE_RESOLVER* PNS_KICAD_IFACE_BASE::GetRuleResolver()
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
return m_ruleResolver;
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
void PNS_KICAD_IFACE::SetHostTool( PCB_TOOL_BASE* aTool )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2017-10-31 11:03:58 +00:00
|
|
|
m_tool = aTool;
|
2019-12-05 13:43:55 +00:00
|
|
|
m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
|
2017-10-31 11:03:58 +00:00
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2019-11-07 14:23:09 +00:00
|
|
|
void PNS_KICAD_IFACE::SetDisplayOptions( const PCB_DISPLAY_OPTIONS* aDispOptions )
|
2017-10-31 11:03:58 +00:00
|
|
|
{
|
|
|
|
m_dispOptions = aDispOptions;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|