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
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-01-31 08:23:20 +00:00
|
|
|
#include <undo_redo_container.h>
|
2016-08-15 15:16:47 +00:00
|
|
|
#include <class_board.h>
|
2018-02-02 20:57:12 +00:00
|
|
|
#include <board_connected_item.h>
|
2018-08-27 13:51:37 +00:00
|
|
|
#include <class_text_mod.h>
|
|
|
|
#include <class_edge_mod.h>
|
2016-08-15 15:16:47 +00:00
|
|
|
#include <class_track.h>
|
2018-02-03 09:39:46 +00:00
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_drawsegment.h>
|
2018-08-27 13:51:37 +00:00
|
|
|
#include <class_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 <gal/graphics_abstraction_layer.h>
|
|
|
|
|
|
|
|
#include <pcb_painter.h>
|
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
#include <geometry/shape_circle.h>
|
2018-02-04 12:09:30 +00:00
|
|
|
#include <geometry/shape_arc.h>
|
2016-08-15 15:16:47 +00:00
|
|
|
|
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"
|
2018-05-03 17:52:42 +00:00
|
|
|
#include "../../include/geometry/shape_simple.h"
|
2016-08-15 15:16:47 +00:00
|
|
|
#include "pns_routing_settings.h"
|
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_segment.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_topology.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:
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* aRouter );
|
2016-08-15 15:16:47 +00:00
|
|
|
virtual ~PNS_PCBNEW_RULE_RESOLVER();
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
virtual bool CollideHoles( const PNS::ITEM* aA, const PNS::ITEM* aB,
|
|
|
|
bool aNeedMTV, VECTOR2I* aMTV ) const override;
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const override;
|
|
|
|
virtual int Clearance( int aNetCode ) const override;
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual int DpCoupledNet( int aNet ) override;
|
|
|
|
virtual int DpNetPolarity( int aNet ) override;
|
|
|
|
virtual bool DpNetPair( PNS::ITEM* aItem, int& aNetP, int& aNetN ) override;
|
2019-07-24 15:19:03 +00:00
|
|
|
|
2018-05-19 00:50:52 +00:00
|
|
|
virtual wxString NetName( int aNet ) override;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
private:
|
2016-08-15 15:16:53 +00:00
|
|
|
struct CLEARANCE_ENT
|
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
int coupledNet;
|
2018-06-17 23:31:00 +00:00
|
|
|
int dpClearance;
|
2016-08-15 15:16:47 +00:00
|
|
|
int clearance;
|
|
|
|
};
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
int holeRadius( const PNS::ITEM* aItem ) const;
|
2016-08-29 17:31:13 +00:00
|
|
|
int localPadClearance( 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS::ROUTER* m_router;
|
|
|
|
BOARD* m_board;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-10-18 15:40:22 +00:00
|
|
|
std::vector<CLEARANCE_ENT> m_netClearanceCache;
|
|
|
|
std::unordered_map<const D_PAD*, int> m_localClearanceCache;
|
2016-08-15 15:16:47 +00:00
|
|
|
int m_defaultClearance;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* aRouter ) :
|
2016-08-15 15:16:47 +00:00
|
|
|
m_router( aRouter ),
|
|
|
|
m_board( aBoard )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS::NODE* world = m_router->GetWorld();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS::TOPOLOGY topo( world );
|
2016-10-18 15:40:22 +00:00
|
|
|
m_netClearanceCache.resize( m_board->GetNetCount() );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
// Build clearance cache for net classes
|
2016-08-15 15:16:47 +00:00
|
|
|
for( unsigned int i = 0; i < m_board->GetNetCount(); i++ )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* ni = m_board->FindNet( i );
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
if( ni == NULL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CLEARANCE_ENT ent;
|
|
|
|
ent.coupledNet = DpCoupledNet( i );
|
|
|
|
|
|
|
|
wxString netClassName = ni->GetClassName();
|
|
|
|
NETCLASSPTR nc = m_board->GetDesignSettings().m_NetClasses.Find( netClassName );
|
|
|
|
|
|
|
|
int clearance = nc->GetClearance();
|
|
|
|
ent.clearance = clearance;
|
2018-06-17 23:31:00 +00:00
|
|
|
ent.dpClearance = nc->GetDiffPairGap();
|
2016-10-18 15:40:22 +00:00
|
|
|
m_netClearanceCache[i] = ent;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2018-06-17 23:31:00 +00:00
|
|
|
wxLogTrace( "PNS", "Add net %u netclass %s clearance %d Diff Pair clearance %d",
|
|
|
|
i, netClassName.mb_str(), clearance, ent.dpClearance );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
// Build clearance cache for pads
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto mod : m_board->Modules() )
|
2016-10-18 15:40:22 +00:00
|
|
|
{
|
|
|
|
auto moduleClearance = mod->GetLocalClearance();
|
|
|
|
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : mod->Pads() )
|
2016-10-18 15:40:22 +00:00
|
|
|
{
|
|
|
|
int padClearance = pad->GetLocalClearance();
|
|
|
|
|
|
|
|
if( padClearance > 0 )
|
|
|
|
m_localClearanceCache[ pad ] = padClearance;
|
|
|
|
|
|
|
|
else if( moduleClearance > 0 )
|
|
|
|
m_localClearanceCache[ pad ] = moduleClearance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 10:46:07 +00:00
|
|
|
auto defaultRule = m_board->GetDesignSettings().m_NetClasses.Find ("Default");
|
|
|
|
|
|
|
|
if( defaultRule )
|
|
|
|
{
|
|
|
|
m_defaultClearance = defaultRule->GetClearance();
|
|
|
|
}
|
2018-07-09 17:15:36 +00:00
|
|
|
else
|
2018-03-07 10:46:07 +00:00
|
|
|
{
|
|
|
|
m_defaultClearance = Millimeter2iu(0.254);
|
|
|
|
}
|
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 )
|
|
|
|
{
|
|
|
|
const D_PAD* pad = dynamic_cast<const D_PAD*>( aItem->Parent() );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PNS_PCBNEW_RULE_RESOLVER::CollideHoles( const PNS::ITEM* aA, const PNS::ITEM* aB,
|
|
|
|
bool aNeedMTV, VECTOR2I* aMTV ) const
|
|
|
|
{
|
|
|
|
VECTOR2I pos_a = aA->Shape()->Centre();
|
|
|
|
VECTOR2I pos_b = aB->Shape()->Centre();
|
|
|
|
|
|
|
|
// Holes with identical locations are allowable
|
|
|
|
if( pos_a == pos_b )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int radius_a = holeRadius( aA );
|
|
|
|
int radius_b = holeRadius( aB );
|
|
|
|
|
|
|
|
// Do both objects have holes?
|
|
|
|
if( radius_a > 0 && radius_b > 0 )
|
|
|
|
{
|
|
|
|
int holeToHoleMin = m_board->GetDesignSettings().m_HoleToHoleMin;
|
|
|
|
|
|
|
|
ecoord min_dist = holeToHoleMin + radius_a + radius_b;
|
|
|
|
ecoord min_dist_sq = min_dist * min_dist;
|
|
|
|
|
|
|
|
const VECTOR2I delta = pos_b - pos_a;
|
|
|
|
|
|
|
|
ecoord dist_sq = delta.SquaredEuclideanNorm();
|
|
|
|
|
|
|
|
if( dist_sq < min_dist_sq )
|
|
|
|
{
|
|
|
|
if( aNeedMTV )
|
|
|
|
*aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::localPadClearance( const PNS::ITEM* aItem ) const
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
|
2016-10-18 15:40:22 +00:00
|
|
|
|
|
|
|
auto i = m_localClearanceCache.find( pad );
|
|
|
|
|
|
|
|
if( i == m_localClearanceCache.end() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return i->second;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
int net_a = aA->Net();
|
2016-10-18 15:40:22 +00:00
|
|
|
int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
|
2016-08-15 15:16:47 +00:00
|
|
|
int net_b = aB->Net();
|
2016-10-18 15:40:22 +00:00
|
|
|
int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2018-06-17 23:31:00 +00:00
|
|
|
// Pad clearance is 0 if the ITEM* is not a pad
|
2016-08-15 15:16:47 +00:00
|
|
|
int pad_a = localPadClearance( aA );
|
|
|
|
int pad_b = localPadClearance( aB );
|
|
|
|
|
2016-10-18 15:40:22 +00:00
|
|
|
if( pad_a > 0 )
|
|
|
|
cl_a = pad_a;
|
|
|
|
|
|
|
|
if( pad_b > 0 )
|
|
|
|
cl_b = pad_b;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
return std::max( cl_a, cl_b );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
int PNS_PCBNEW_RULE_RESOLVER::Clearance( int aNetCode ) const
|
|
|
|
{
|
|
|
|
if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() )
|
|
|
|
return m_netClearanceCache[aNetCode].clearance;
|
|
|
|
|
|
|
|
return m_defaultClearance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return net->GetNet();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( PNS::ITEM* aItem, int& aNetP, int& aNetN )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
|
|
|
|
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 )
|
|
|
|
return false;
|
|
|
|
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;
|
|
|
|
|
|
|
|
aNetP = netInfoP->GetNet();
|
|
|
|
aNetN = netInfoN->GetNet();
|
|
|
|
|
|
|
|
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:
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS_PCBNEW_DEBUG_DECORATOR( KIGFX::VIEW* aView = NULL ): PNS::DEBUG_DECORATOR(),
|
2016-08-15 15:16:48 +00:00
|
|
|
m_view( NULL ), m_items( NULL )
|
|
|
|
{
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddPoint( VECTOR2I aP, int aColor ) override
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN l;
|
|
|
|
|
|
|
|
l.Append( aP - VECTOR2I( -50000, -50000 ) );
|
|
|
|
l.Append( aP + VECTOR2I( -50000, -50000 ) );
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
AddLine( l, aColor, 10000 );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
|
|
|
l.Clear();
|
|
|
|
l.Append( aP - VECTOR2I( 50000, -50000 ) );
|
|
|
|
l.Append( aP + VECTOR2I( 50000, -50000 ) );
|
|
|
|
|
|
|
|
AddLine( l, aColor, 10000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddBox( BOX2I aB, int aColor ) override
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSegment( SEG aS, int aColor ) override
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN l;
|
|
|
|
|
|
|
|
l.Append( aS.A );
|
|
|
|
l.Append( aS.B );
|
|
|
|
|
|
|
|
AddLine( l, aColor, 10000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddDirections( VECTOR2D aP, int aMask, int aColor ) override
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddLine( const SHAPE_LINE_CHAIN& aLine, int aType, int aWidth ) override
|
|
|
|
{
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS::DEBUG_DECORATOR* PNS_KICAD_IFACE::GetDebugDecorator()
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
return m_debugDecorator;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
PNS_KICAD_IFACE::PNS_KICAD_IFACE()
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
m_ruleResolver = nullptr;
|
2016-08-15 15:16:48 +00:00
|
|
|
m_board = nullptr;
|
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;
|
|
|
|
m_router = nullptr;
|
2016-08-15 15:16:48 +00:00
|
|
|
m_debugDecorator = 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
|
|
|
|
|
|
|
PNS_KICAD_IFACE::~PNS_KICAD_IFACE()
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_ruleResolver;
|
|
|
|
delete m_debugDecorator;
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2016-08-17 13:09:48 +00:00
|
|
|
if( m_previewItems )
|
|
|
|
{
|
|
|
|
m_previewItems->FreeItems();
|
|
|
|
delete m_previewItems;
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE::syncPad( D_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
|
|
|
|
|
|
|
// ignore non-copper pads
|
2016-08-15 15:16:53 +00:00
|
|
|
if( ( aPad->GetLayerSet() & LSET::AllCuMask()).none() )
|
2016-08-15 15:16:47 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch( aPad->GetAttribute() )
|
|
|
|
{
|
|
|
|
case PAD_ATTRIB_STANDARD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_ATTRIB_SMD:
|
|
|
|
case PAD_ATTRIB_HOLE_NOT_PLATED:
|
|
|
|
case PAD_ATTRIB_CONN:
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
if( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !is_copper )
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
solid->SetLayers( layers );
|
|
|
|
solid->SetNet( aPad->GetNetCode() );
|
|
|
|
solid->SetParent( aPad );
|
|
|
|
|
|
|
|
wxPoint wx_c = aPad->ShapePos();
|
|
|
|
wxSize wx_sz = aPad->GetSize();
|
|
|
|
wxPoint offset = aPad->GetOffset();
|
|
|
|
|
|
|
|
VECTOR2I c( wx_c.x, wx_c.y );
|
|
|
|
VECTOR2I sz( wx_sz.x, wx_sz.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 ) );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
double orient = aPad->GetOrientation() / 10.0;
|
|
|
|
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CIRCLE )
|
|
|
|
{
|
|
|
|
solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
|
|
|
|
}
|
2017-12-19 10:13:28 +00:00
|
|
|
else if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
outline.Append( aPad->GetCustomShapeAsPolygon() );
|
|
|
|
aPad->CustomShapeAsPolygonToBoardPosition( &outline, wx_c, aPad->GetOrientation() );
|
|
|
|
|
2018-05-03 17:52:42 +00:00
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
2017-12-19 10:13:28 +00:00
|
|
|
|
2018-05-03 17:52:42 +00:00
|
|
|
for( auto iter = outline.CIterate( 0 ); iter; iter++ )
|
|
|
|
shape->Append( *iter );
|
2017-12-19 10:13:28 +00:00
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( orient == 0.0 || orient == 90.0 || orient == 180.0 || orient == 270.0 )
|
|
|
|
{
|
|
|
|
if( orient == 90.0 || orient == 270.0 )
|
|
|
|
sz = VECTOR2I( sz.y, sz.x );
|
|
|
|
|
|
|
|
switch( aPad->GetShape() )
|
|
|
|
{
|
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
if( sz.x == sz.y )
|
|
|
|
solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VECTOR2I delta;
|
|
|
|
|
|
|
|
if( sz.x > sz.y )
|
|
|
|
delta = VECTOR2I( ( sz.x - sz.y ) / 2, 0 );
|
|
|
|
else
|
|
|
|
delta = VECTOR2I( 0, ( sz.y - sz.x ) / 2 );
|
|
|
|
|
|
|
|
SHAPE_SEGMENT* shape = new SHAPE_SEGMENT( c - delta, c + delta,
|
|
|
|
std::min( sz.x, sz.y ) );
|
|
|
|
solid->SetShape( shape );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
solid->SetShape( new SHAPE_RECT( c - sz / 2, sz.x, sz.y ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
{
|
|
|
|
wxPoint coords[4];
|
|
|
|
aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
|
2018-05-03 17:52:42 +00:00
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
|
|
|
shape->Append( wx_c + coords[ii] );
|
|
|
|
}
|
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-29 07:13:07 +00:00
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2016-08-15 15:16:47 +00:00
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outline;
|
2019-05-14 12:39:34 +00:00
|
|
|
aPad->BuildPadShapePolygon( outline, wxSize( 0, 0 ) );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
// TransformRoundRectToPolygon creates only one convex polygon
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
2018-05-03 17:52:42 +00:00
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
2018-08-29 07:13:07 +00:00
|
|
|
shape->Append( poly.Point( ii ) );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "unsupported pad shape" );
|
2016-08-30 15:28:35 +00:00
|
|
|
return nullptr;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( aPad->GetShape() )
|
|
|
|
{
|
2017-12-19 10:13:28 +00:00
|
|
|
// PAD_SHAPE_CIRCLE and PAD_SHAPE_CUSTOM already handled above
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
if( sz.x == sz.y )
|
|
|
|
solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint start;
|
|
|
|
wxPoint end;
|
|
|
|
wxPoint corner;
|
|
|
|
|
2018-05-03 17:52:42 +00:00
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
int w = aPad->BuildSegmentFromOvalShape( start, end, 0.0, wxSize( 0, 0 ) );
|
|
|
|
|
|
|
|
if( start.y == 0 )
|
|
|
|
corner = wxPoint( start.x, -( w / 2 ) );
|
|
|
|
else
|
|
|
|
corner = wxPoint( w / 2, start.y );
|
|
|
|
|
|
|
|
RotatePoint( &start, aPad->GetOrientation() );
|
|
|
|
RotatePoint( &corner, aPad->GetOrientation() );
|
|
|
|
shape->Append( wx_c + corner );
|
|
|
|
|
|
|
|
for( int rot = 100; rot <= 1800; rot += 100 )
|
|
|
|
{
|
|
|
|
wxPoint p( corner );
|
|
|
|
RotatePoint( &p, start, rot );
|
|
|
|
shape->Append( wx_c + p );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( end.y == 0 )
|
|
|
|
corner = wxPoint( end.x, w / 2 );
|
|
|
|
else
|
|
|
|
corner = wxPoint( -( w / 2 ), end.y );
|
|
|
|
|
|
|
|
RotatePoint( &end, aPad->GetOrientation() );
|
|
|
|
RotatePoint( &corner, aPad->GetOrientation() );
|
|
|
|
shape->Append( wx_c + corner );
|
|
|
|
|
|
|
|
for( int rot = 100; rot <= 1800; rot += 100 )
|
|
|
|
{
|
|
|
|
wxPoint p( corner );
|
|
|
|
RotatePoint( &p, end, rot );
|
|
|
|
shape->Append( wx_c + p );
|
|
|
|
}
|
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
{
|
|
|
|
wxPoint coords[4];
|
|
|
|
aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
|
|
|
|
|
2018-05-03 17:52:42 +00:00
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
2016-08-15 15:16:47 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
|
|
|
shape->Append( wx_c + coords[ii] );
|
|
|
|
}
|
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-29 07:13:07 +00:00
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2016-08-15 15:16:47 +00:00
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET outline;
|
2019-05-14 12:39:34 +00:00
|
|
|
aPad->BuildPadShapePolygon( outline, wxSize( 0, 0 ) );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
// TransformRoundRectToPolygon creates only one convex polygon
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
2018-05-03 17:52:42 +00:00
|
|
|
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
|
|
|
{
|
|
|
|
shape->Append( wxPoint( poly.Point( ii ).x, poly.Point( ii ).y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
break;
|
2016-08-15 15:16:53 +00:00
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
default:
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "unsupported pad shape" );
|
2016-08-30 15:28:35 +00:00
|
|
|
return nullptr;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return solid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE::syncTrack( TRACK* aTrack )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-30 15:28:35 +00:00
|
|
|
std::unique_ptr< PNS::SEGMENT > segment(
|
|
|
|
new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() )
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE::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 );
|
2016-08-30 15:28:35 +00:00
|
|
|
std::unique_ptr<PNS::VIA> via( new PNS::VIA(
|
2016-08-15 15:16:47 +00:00
|
|
|
aVia->GetPosition(),
|
2016-08-29 17:31:13 +00:00
|
|
|
LAYER_RANGE( top, bottom ),
|
2016-08-15 15:16:47 +00:00
|
|
|
aVia->GetWidth(),
|
|
|
|
aVia->GetDrillValue(),
|
|
|
|
aVia->GetNetCode(),
|
2016-08-30 15:28:35 +00:00
|
|
|
aVia->GetViaType() )
|
|
|
|
);
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
via->SetParent( aVia );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
if( aVia->IsLocked() )
|
2016-08-30 15:28:35 +00:00
|
|
|
via->Mark( PNS::MK_LOCKED );
|
|
|
|
|
|
|
|
return via;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 09:24:57 +00:00
|
|
|
|
2018-02-03 09:39:46 +00:00
|
|
|
bool PNS_KICAD_IFACE::syncZone( PNS::NODE* aWorld, ZONE_CONTAINER* aZone )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
2018-02-19 09:24:57 +00:00
|
|
|
// TODO handle no-via restriction
|
|
|
|
if( !aZone->GetIsKeepout() || !aZone->GetDoNotAllowTracks() )
|
2018-02-03 09:39:46 +00:00
|
|
|
return false;
|
|
|
|
|
2019-07-13 22:34:09 +00:00
|
|
|
// Some intersecting zones, despite being on the same layer with the same net, cannot be
|
|
|
|
// merged due to other parameters such as fillet radius. The copper pour will end up
|
|
|
|
// effectively merged though, so we want to keep the corners of such intersections sharp.
|
|
|
|
std::set<VECTOR2I> colinearCorners;
|
|
|
|
aZone->GetColinearCorners( m_board, colinearCorners );
|
|
|
|
|
|
|
|
aZone->BuildSmoothedPoly( poly, &colinearCorners );
|
2018-02-03 09:39:46 +00:00
|
|
|
poly.CacheTriangulation();
|
|
|
|
|
2018-02-18 22:23:24 +00:00
|
|
|
if( !poly.IsTriangulationUpToDate() )
|
|
|
|
{
|
2018-03-02 15:52:45 +00:00
|
|
|
KIDIALOG dlg( nullptr, wxString::Format( _( "Malformed keep-out zone at (%d, %d)" ),
|
|
|
|
aZone->GetPosition().x, aZone->GetPosition().y ), KIDIALOG::KD_WARNING );
|
|
|
|
dlg.ShowDetailedText(
|
|
|
|
wxString::Format( _( "%s\nThis zone cannot be handled by the track layout tool.\n"
|
2018-04-10 10:52:12 +00:00
|
|
|
"Please verify it is not a self-intersecting polygon." ),
|
2018-06-06 16:06:08 +00:00
|
|
|
aZone->GetSelectMenuText( MILLIMETRES ) ) );
|
2018-08-29 22:37:20 +00:00
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
2018-02-22 10:19:33 +00:00
|
|
|
dlg.ShowModal();
|
|
|
|
|
2018-02-18 22:23:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-03 09:39:46 +00:00
|
|
|
LSET layers = aZone->GetLayerSet();
|
|
|
|
|
2018-02-04 12:09:30 +00:00
|
|
|
for( int layer = F_Cu; layer <= B_Cu; layer++ )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
|
|
|
if ( ! layers[layer] )
|
|
|
|
continue;
|
|
|
|
|
2018-02-04 12:09:30 +00:00
|
|
|
for( int outline = 0; outline < poly.OutlineCount(); outline++ )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
|
|
|
auto tri = poly.TriangulatedPolygon( outline );
|
|
|
|
|
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 );
|
2018-05-03 17:52:42 +00:00
|
|
|
auto triShape = new SHAPE_SIMPLE;
|
2018-02-03 09:39:46 +00:00
|
|
|
|
|
|
|
triShape->Append( a );
|
|
|
|
triShape->Append( b );
|
|
|
|
triShape->Append( c );
|
|
|
|
|
|
|
|
std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
bool PNS_KICAD_IFACE::syncTextItem( PNS::NODE* aWorld, EDA_TEXT* aText, PCB_LAYER_ID aLayer )
|
|
|
|
{
|
|
|
|
if( !IsCopperLayer( aLayer ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int textWidth = aText->GetThickness();
|
|
|
|
std::vector<wxPoint> textShape;
|
|
|
|
|
|
|
|
aText->TransformTextShapeToSegmentList( textShape );
|
|
|
|
|
|
|
|
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] );
|
|
|
|
std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
|
|
|
|
|
|
|
|
solid->SetLayer( aLayer );
|
|
|
|
solid->SetNet( -1 );
|
|
|
|
solid->SetParent( nullptr );
|
|
|
|
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;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-04 12:09:30 +00:00
|
|
|
bool PNS_KICAD_IFACE::syncGraphicalItem( PNS::NODE* aWorld, DRAWSEGMENT* aItem )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
2018-02-04 12:09:30 +00:00
|
|
|
std::vector<SHAPE_SEGMENT*> segs;
|
|
|
|
|
2018-08-27 13:51:37 +00:00
|
|
|
if( aItem->GetLayer() != Edge_Cuts && !IsCopperLayer( aItem->GetLayer() ) )
|
2018-02-04 12:09:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch( aItem->GetShape() )
|
|
|
|
{
|
2018-12-06 03:39:05 +00:00
|
|
|
case S_ARC:
|
|
|
|
{
|
|
|
|
SHAPE_ARC arc( aItem->GetCenter(), aItem->GetArcStart(), aItem->GetAngle() / 10.0 );
|
|
|
|
auto l = arc.ConvertToPolyline();
|
2018-02-18 20:00:28 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
2018-02-04 12:09:30 +00:00
|
|
|
{
|
2018-12-06 03:39:05 +00:00
|
|
|
SHAPE_SEGMENT* seg = new SHAPE_SEGMENT( l.CSegment( i ), aItem->GetWidth() );
|
2018-02-04 12:09:30 +00:00
|
|
|
segs.push_back( seg );
|
|
|
|
}
|
2018-02-18 20:00:28 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-18 20:00:28 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
case S_SEGMENT:
|
|
|
|
segs.push_back(
|
|
|
|
new SHAPE_SEGMENT( aItem->GetStart(), aItem->GetEnd(), aItem->GetWidth() ) );
|
2018-02-18 20:00:28 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
break;
|
2018-02-18 20:00:28 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
case S_CIRCLE:
|
|
|
|
{
|
|
|
|
// SHAPE_CIRCLE has no ConvertToPolyline() method, so use a 360.0 SHAPE_ARC
|
|
|
|
SHAPE_ARC circle( aItem->GetCenter(), aItem->GetEnd(), 360.0 );
|
|
|
|
auto l = circle.ConvertToPolyline();
|
2018-02-18 20:00:28 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
|
|
|
segs.push_back( new SHAPE_SEGMENT( l.CSegment( i ), aItem->GetWidth() ) );
|
2018-12-05 11:56:34 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case S_CURVE:
|
|
|
|
{
|
|
|
|
aItem->RebuildBezierToSegmentsPointsList( aItem->GetWidth() );
|
|
|
|
auto pts = aItem->GetBezierPoints();
|
|
|
|
|
|
|
|
for( size_t ii = 1; ii < pts.size(); ii++ )
|
|
|
|
{
|
|
|
|
segs.push_back( new SHAPE_SEGMENT(
|
|
|
|
VECTOR2I( pts[ii - 1] ), VECTOR2I( pts[ii] ), aItem->GetWidth() ) );
|
2018-12-05 11:56:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-12-06 03:39:05 +00:00
|
|
|
}
|
2018-07-09 17:15:36 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
case S_POLYGON:
|
|
|
|
if( !aItem->IsPolygonFilled() )
|
2018-12-05 11:56:34 +00:00
|
|
|
{
|
2018-12-06 03:39:05 +00:00
|
|
|
auto poly = aItem->BuildPolyPointsList();
|
|
|
|
for( size_t ii = 1; ii < poly.size(); ii++ )
|
2018-12-05 11:56:34 +00:00
|
|
|
{
|
|
|
|
segs.push_back( new SHAPE_SEGMENT(
|
2018-12-06 03:39:05 +00:00
|
|
|
VECTOR2I( poly[ii - 1] ), VECTOR2I( poly[ii] ), aItem->GetWidth() ) );
|
2018-07-09 17:15:36 +00:00
|
|
|
}
|
2018-12-06 03:39:05 +00:00
|
|
|
|
|
|
|
segs.push_back( new SHAPE_SEGMENT(
|
|
|
|
VECTOR2I( poly.back() ), VECTOR2I( poly.front() ), aItem->GetWidth() ) );
|
2018-12-05 11:56:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-07-09 17:15:36 +00:00
|
|
|
|
2018-12-06 03:39:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-02-04 12:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( auto seg : segs )
|
|
|
|
{
|
2018-04-24 23:28:13 +00:00
|
|
|
std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2018-08-27 13:51:37 +00:00
|
|
|
if( aItem->GetLayer() == Edge_Cuts )
|
|
|
|
solid->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
|
|
|
|
else
|
|
|
|
solid->SetLayer( aItem->GetLayer() );
|
|
|
|
|
2018-04-24 23:28:13 +00:00
|
|
|
solid->SetNet( -1 );
|
|
|
|
solid->SetParent( nullptr );
|
|
|
|
solid->SetShape( seg );
|
|
|
|
solid->SetRoutable( false );
|
2018-02-04 12:09:30 +00:00
|
|
|
|
2018-04-24 23:28:13 +00:00
|
|
|
aWorld->Add( std::move( solid ) );
|
2018-02-04 12:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-02-03 09:39:46 +00:00
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2019-08-15 07:21:48 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
void PNS_KICAD_IFACE::SetBoard( BOARD* aBoard )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-15 07:21:48 +00:00
|
|
|
bool PNS_KICAD_IFACE::IsAnyLayerVisible( const LAYER_RANGE& aLayer )
|
|
|
|
{
|
|
|
|
if( !m_view )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( int i = aLayer.Start(); i <= aLayer.End(); i++ )
|
|
|
|
if( m_view->IsLayerVisible( i ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2017-12-18 17:51:44 +00:00
|
|
|
int worstPadClearance = 0;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-03 09:39:46 +00:00
|
|
|
for( auto gitem : m_board->Drawings() )
|
|
|
|
{
|
2018-02-09 12:00:57 +00:00
|
|
|
if ( gitem->Type() == PCB_LINE_T )
|
|
|
|
{
|
|
|
|
syncGraphicalItem( aWorld, static_cast<DRAWSEGMENT*>( gitem ) );
|
|
|
|
}
|
2018-08-27 13:51:37 +00:00
|
|
|
else if( gitem->Type() == PCB_TEXT_T )
|
|
|
|
{
|
2018-10-11 12:12:22 +00:00
|
|
|
syncTextItem( aWorld, static_cast<TEXTE_PCB*>( gitem ), gitem->GetLayer() );
|
2018-08-27 13:51:37 +00:00
|
|
|
}
|
2018-02-03 09:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( auto zone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
syncZone( aWorld, zone );
|
|
|
|
}
|
|
|
|
|
2017-12-18 17:51:44 +00:00
|
|
|
for( auto module : m_board->Modules() )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2017-12-18 17:51:44 +00:00
|
|
|
for( auto pad : module->Pads() )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2019-01-12 15:24:00 +00:00
|
|
|
if( auto solid = syncPad( pad ) )
|
2016-08-30 15:28:35 +00:00
|
|
|
aWorld->Add( std::move( solid ) );
|
2017-12-18 17:51:44 +00:00
|
|
|
|
|
|
|
worstPadClearance = std::max( worstPadClearance, pad->GetLocalClearance() );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
2018-08-27 13:51:37 +00:00
|
|
|
|
|
|
|
syncTextItem( aWorld, &module->Reference(), module->Reference().GetLayer() );
|
|
|
|
syncTextItem( aWorld, &module->Value(), module->Value().GetLayer() );
|
|
|
|
|
2018-11-03 17:31:07 +00:00
|
|
|
if( module->IsNetTie() )
|
|
|
|
continue;
|
|
|
|
|
2018-08-27 13:51:37 +00:00
|
|
|
for( auto mgitem : module->GraphicalItems() )
|
|
|
|
{
|
|
|
|
if( mgitem->Type() == PCB_MODULE_EDGE_T )
|
|
|
|
{
|
|
|
|
syncGraphicalItem( aWorld, static_cast<DRAWSEGMENT*>( mgitem ) );
|
|
|
|
}
|
|
|
|
else if( mgitem->Type() == PCB_MODULE_TEXT_T )
|
|
|
|
{
|
|
|
|
syncTextItem( aWorld, dynamic_cast<TEXTE_MODULE*>( mgitem ), mgitem->GetLayer() );
|
|
|
|
}
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 17:51:44 +00:00
|
|
|
for( auto 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
|
|
|
}
|
|
|
|
else if( type == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-12-18 17:51:44 +00:00
|
|
|
int worstRuleClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_ruleResolver;
|
2016-08-15 15:16:47 +00:00
|
|
|
m_ruleResolver = new PNS_PCBNEW_RULE_RESOLVER( m_board, m_router );
|
|
|
|
|
|
|
|
aWorld->SetRuleResolver( m_ruleResolver );
|
2017-12-18 17:51:44 +00:00
|
|
|
aWorld->SetMaxClearance( 4 * std::max(worstPadClearance, worstRuleClearance ) );
|
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
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2019-04-08 04:24:30 +00:00
|
|
|
void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aColor, int aClearance, bool aEdit )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "DisplayItem %p", aItem );
|
2016-08-15 15:16:48 +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( aColor >= 0 )
|
|
|
|
pitem->SetColor( KIGFX::COLOR4D( aColor ) );
|
|
|
|
|
|
|
|
if( aClearance >= 0 )
|
2017-01-25 09:33:49 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
pitem->SetClearance( aClearance );
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
if( m_dispOptions )
|
|
|
|
{
|
2019-04-08 04:24:30 +00:00
|
|
|
switch( m_dispOptions->m_ShowTrackClearanceMode )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void PNS_KICAD_IFACE::HideItem( PNS::ITEM* aItem )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
BOARD_CONNECTED_ITEM* parent = aItem->Parent();
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
BOARD_CONNECTED_ITEM* parent = aItem->Parent();
|
|
|
|
|
|
|
|
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
|
|
|
|
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() )
|
|
|
|
{
|
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()
|
|
|
|
via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
|
|
|
|
ToLAYER_ID( via->Layers().End() ) );
|
|
|
|
newBI = via_board;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( newBI )
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
2016-12-02 17:58:12 +00:00
|
|
|
EraseView();
|
2018-06-13 00:05:25 +00:00
|
|
|
m_commit->Push( _( "Added a track" ) );
|
2017-10-31 11:03:58 +00:00
|
|
|
m_commit.reset( new 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 ) ;
|
2016-08-15 15:16:47 +00:00
|
|
|
m_view->Add( m_previewItems );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2016-08-17 13:09:48 +00:00
|
|
|
delete m_debugDecorator;
|
2016-08-15 15:16:48 +00:00
|
|
|
m_debugDecorator = new PNS_PCBNEW_DEBUG_DECORATOR();
|
2016-08-15 15:16:53 +00:00
|
|
|
m_debugDecorator->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
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
PNS::RULE_RESOLVER* PNS_KICAD_IFACE::GetRuleResolver()
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
return m_ruleResolver;
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void PNS_KICAD_IFACE::SetRouter( PNS::ROUTER* aRouter )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
m_router = aRouter;
|
|
|
|
}
|
|
|
|
|
2016-06-21 15:06:28 +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;
|
|
|
|
m_commit.reset( new BOARD_COMMIT( m_tool ) );
|
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2017-10-31 11:03:58 +00:00
|
|
|
void PNS_KICAD_IFACE::SetDisplayOptions( PCB_DISPLAY_OPTIONS *aDispOptions )
|
|
|
|
{
|
|
|
|
m_dispOptions = aDispOptions;
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|