KiCad PCB EDA Suite
PNS_KICAD_IFACE Class Reference

#include <pns_kicad_iface.h>

Inheritance diagram for PNS_KICAD_IFACE:
PNS_KICAD_IFACE_BASE PNS::ROUTER_IFACE

Classes

struct  OFFSET
 

Public Member Functions

 PNS_KICAD_IFACE ()
 
 ~PNS_KICAD_IFACE ()
 
void SetHostTool (PCB_TOOL_BASE *aTool)
 
void SetView (KIGFX::VIEW *aView)
 
void EraseView () override
 
bool IsAnyLayerVisible (const LAYER_RANGE &aLayer) const override
 
bool IsItemVisible (const PNS::ITEM *aItem) const override
 
void HideItem (PNS::ITEM *aItem) override
 
void DisplayItem (const PNS::ITEM *aItem, int aClearance, bool aEdit=false, bool aIsHeadTrace=false) override
 
void DisplayRatline (const SHAPE_LINE_CHAIN &aRatline, int aNetCode) override
 
void Commit () override
 
void AddItem (PNS::ITEM *aItem) override
 
void UpdateItem (PNS::ITEM *aItem) override
 
void RemoveItem (PNS::ITEM *aItem) override
 
void UpdateNet (int aNetCode) override
 
EDA_UNITS GetUnits () const override
 
void SetCommitFlags (int aCommitFlags)
 
void SetBoard (BOARD *aBoard)
 
void SyncWorld (PNS::NODE *aWorld) override
 
bool IsFlashedOnLayer (const PNS::ITEM *aItem, int aLayer) const override
 
bool ImportSizes (PNS::SIZES_SETTINGS &aSizes, PNS::ITEM *aStartItem, int aNet) override
 
int StackupHeight (int aFirstLayer, int aSecondLayer) const override
 
void SetDebugDecorator (PNS::DEBUG_DECORATOR *aDec)
 
void SetStartLayer (int aLayer)
 
virtual PNS::NODEGetWorld () const override
 
BOARDGetBoard () const
 
PNS::RULE_RESOLVERGetRuleResolver () override
 
PNS::DEBUG_DECORATORGetDebugDecorator () override
 

Protected Member Functions

std::unique_ptr< PNS::SOLIDsyncPad (PAD *aPad)
 
std::unique_ptr< PNS::SEGMENTsyncTrack (PCB_TRACK *aTrack)
 
std::unique_ptr< PNS::ARCsyncArc (PCB_ARC *aArc)
 
std::unique_ptr< PNS::VIAsyncVia (PCB_VIA *aVia)
 
bool syncTextItem (PNS::NODE *aWorld, EDA_TEXT *aText, PCB_LAYER_ID aLayer)
 
bool syncGraphicalItem (PNS::NODE *aWorld, PCB_SHAPE *aItem)
 
bool syncZone (PNS::NODE *aWorld, ZONE *aZone, SHAPE_POLY_SET *aBoardOutline)
 
bool inheritTrackWidth (PNS::ITEM *aItem, int *aInheritedWidth)
 

Protected Attributes

PNS_PCBNEW_RULE_RESOLVERm_ruleResolver
 
PNS::DEBUG_DECORATORm_debugDecorator
 
PNS::NODEm_world
 
BOARDm_board
 
int m_startLayer
 

Private Attributes

std::map< PAD *, OFFSETm_fpOffsets
 
KIGFX::VIEWm_view
 
KIGFX::VIEW_GROUPm_previewItems
 
std::unordered_set< BOARD_ITEM * > m_hiddenItems
 
PCB_TOOL_BASEm_tool
 
std::unique_ptr< BOARD_COMMITm_commit
 
int m_commitFlags
 

Detailed Description

Definition at line 105 of file pns_kicad_iface.h.

Constructor & Destructor Documentation

◆ PNS_KICAD_IFACE()

PNS_KICAD_IFACE::PNS_KICAD_IFACE ( )

Definition at line 1040 of file pns_kicad_iface.cpp.

1041{
1042 m_tool = nullptr;
1043 m_view = nullptr;
1044 m_previewItems = nullptr;
1045 m_commitFlags = 0;
1046}
KIGFX::VIEW * m_view
PCB_TOOL_BASE * m_tool
KIGFX::VIEW_GROUP * m_previewItems

References m_commitFlags, m_previewItems, m_tool, and m_view.

◆ ~PNS_KICAD_IFACE()

PNS_KICAD_IFACE::~PNS_KICAD_IFACE ( )

Definition at line 1054 of file pns_kicad_iface.cpp.

1055{
1056 delete m_ruleResolver;
1057 delete m_debugDecorator;
1058
1059 if( m_previewItems )
1060 {
1062 delete m_previewItems;
1063 }
1064}
void FreeItems()
Free all the items that were added to the group.
Definition: view_group.cpp:191
PNS::DEBUG_DECORATOR * m_debugDecorator
PNS_PCBNEW_RULE_RESOLVER * m_ruleResolver

References KIGFX::VIEW_GROUP::FreeItems(), PNS_KICAD_IFACE_BASE::m_debugDecorator, m_previewItems, and PNS_KICAD_IFACE_BASE::m_ruleResolver.

Member Function Documentation

◆ AddItem()

void PNS_KICAD_IFACE::AddItem ( PNS::ITEM aItem)
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1802 of file pns_kicad_iface.cpp.

1803{
1804 BOARD_CONNECTED_ITEM* newBI = nullptr;
1805
1806 switch( aItem->Kind() )
1807 {
1808 case PNS::ITEM::ARC_T:
1809 {
1810 PNS::ARC* arc = static_cast<PNS::ARC*>( aItem );
1811 PCB_ARC* new_arc = new PCB_ARC( m_board, static_cast<const SHAPE_ARC*>( arc->Shape() ) );
1812 new_arc->SetWidth( arc->Width() );
1813 new_arc->SetLayer( ToLAYER_ID( arc->Layers().Start() ) );
1814 new_arc->SetNetCode( std::max<int>( 0, arc->Net() ) );
1815 newBI = new_arc;
1816 break;
1817 }
1818
1820 {
1821 PNS::SEGMENT* seg = static_cast<PNS::SEGMENT*>( aItem );
1822 PCB_TRACK* track = new PCB_TRACK( m_board );
1823 const SEG& s = seg->Seg();
1824 track->SetStart( wxPoint( s.A.x, s.A.y ) );
1825 track->SetEnd( wxPoint( s.B.x, s.B.y ) );
1826 track->SetWidth( seg->Width() );
1827 track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) );
1828 track->SetNetCode( seg->Net() > 0 ? seg->Net() : 0 );
1829 newBI = track;
1830 break;
1831 }
1832
1833 case PNS::ITEM::VIA_T:
1834 {
1835 PCB_VIA* via_board = new PCB_VIA( m_board );
1836 PNS::VIA* via = static_cast<PNS::VIA*>( aItem );
1837 via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
1838 via_board->SetWidth( via->Diameter() );
1839 via_board->SetDrill( via->Drill() );
1840 via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
1841 via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
1842 via_board->SetIsFree( via->IsFree() );
1843 via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
1844 ToLAYER_ID( via->Layers().End() ) );
1845 newBI = via_board;
1846 break;
1847 }
1848
1849 case PNS::ITEM::SOLID_T:
1850 {
1851 PAD* pad = static_cast<PAD*>( aItem->Parent() );
1852 VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1853
1854 m_fpOffsets[ pad ].p_new = pos;
1855 return;
1856 }
1857
1858 default:
1859 break;
1860 }
1861
1862 if( newBI )
1863 {
1864 //newBI->SetLocalRatsnestVisible( m_dispOptions->m_ShowGlobalRatsnest );
1865 aItem->SetParent( newBI );
1866 newBI->ClearFlags();
1867
1868 m_commit->Add( newBI );
1869 }
1870}
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:214
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:141
int Start() const
Definition: pns_layerset.h:82
Definition: pad.h:59
void SetWidth(int aWidth)
Definition: pcb_track.h:106
void SetEnd(const VECTOR2I &aEnd)
Definition: pcb_track.h:109
void SetStart(const VECTOR2I &aStart)
Definition: pcb_track.h:112
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: pcb_track.h:515
void SetIsFree(bool aFree=true)
Definition: pcb_track.h:544
void SetPosition(const VECTOR2I &aPoint) override
Definition: pcb_track.h:442
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_layer contains the top layer, the other layer is in m_bottomLayer.
Definition: pcb_track.cpp:551
void SetViaType(VIATYPE aViaType)
Definition: pcb_track.h:394
int Width() const override
Definition: pns_arc.h:87
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition: pns_arc.h:77
BOARD_ITEM * Parent() const
Definition: pns_item.h:151
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:132
@ SOLID_T
Definition: pns_item.h:63
@ SEGMENT_T
Definition: pns_item.h:66
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:150
const LAYER_RANGE & Layers() const
Definition: pns_item.h:156
int Net() const
Definition: pns_item.h:154
const SEG & Seg() const
Definition: pns_segment.h:84
int Width() const override
Definition: pns_segment.h:79
std::map< PAD *, OFFSET > m_fpOffsets
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932

References SEG::A, PNS::ITEM::ARC_T, SEG::B, EDA_ITEM::ClearFlags(), PNS::ITEM::Kind(), PNS::ITEM::Layers(), PNS_KICAD_IFACE_BASE::m_board, m_commit, m_fpOffsets, PNS::ITEM::Net(), pad, PNS::ITEM::Parent(), PNS::SEGMENT::Seg(), PNS::ITEM::SEGMENT_T, PCB_VIA::SetDrill(), PCB_TRACK::SetEnd(), PCB_VIA::SetIsFree(), BOARD_ITEM::SetLayer(), PCB_VIA::SetLayerPair(), BOARD_CONNECTED_ITEM::SetNetCode(), PNS::ITEM::SetParent(), PCB_VIA::SetPosition(), PCB_TRACK::SetStart(), PCB_VIA::SetViaType(), PCB_TRACK::SetWidth(), PNS::ARC::Shape(), PNS::ITEM::SOLID_T, LAYER_RANGE::Start(), ToLAYER_ID(), via, PNS::ITEM::VIA_T, PNS::ARC::Width(), PNS::SEGMENT::Width(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Commit()

void PNS_KICAD_IFACE::Commit ( )
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1873 of file pns_kicad_iface.cpp.

1874{
1875 std::set<FOOTPRINT*> processedFootprints;
1876
1877 EraseView();
1878
1879 for( const std::pair<const PAD*, OFFSET>& fpOffset : m_fpOffsets )
1880 {
1881 VECTOR2I offset = fpOffset.second.p_new - fpOffset.second.p_old;
1882 FOOTPRINT* footprint = fpOffset.first->GetParent();
1883 VECTOR2I p_orig = footprint->GetPosition();
1884 VECTOR2I p_new = p_orig + offset;
1885
1886 if( processedFootprints.find( footprint ) != processedFootprints.end() )
1887 continue;
1888
1889 processedFootprints.insert( footprint );
1890 m_commit->Modify( footprint );
1891 footprint->SetPosition( p_new );
1892 }
1893
1894 m_fpOffsets.clear();
1895
1896 m_commit->Push( _( "Interactive Router" ), m_commitFlags );
1897 m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1898}
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:163
void SetPosition(const VECTOR2I &aPos) override
Definition: footprint.cpp:1670
VECTOR2I GetPosition() const override
Definition: footprint.h:188
void EraseView() override
#define _(s)

References _, EraseView(), BOARD_ITEM::GetParent(), FOOTPRINT::GetPosition(), m_commit, m_commitFlags, m_fpOffsets, m_tool, and FOOTPRINT::SetPosition().

◆ DisplayItem()

void PNS_KICAD_IFACE::DisplayItem ( const PNS::ITEM aItem,
int  aClearance,
bool  aEdit = false,
bool  aIsHeadTrace = false 
)
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1607 of file pns_kicad_iface.cpp.

1608{
1609 if( aItem->IsVirtual() )
1610 return;
1611
1612 ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view );
1613
1614 // Note: SEGMENT_T is used for placed tracks; LINE_T is used for the routing head
1616 static int tracksOrVias = tracks | PNS::ITEM::VIA_T;
1617
1618 if( aClearance >= 0 )
1619 {
1620 pitem->SetClearance( aClearance );
1621
1622 auto* settings = static_cast<PCBNEW_SETTINGS*>( m_tool->GetManager()->GetSettings() );
1623
1624 switch( settings->m_Display.m_TrackClearance )
1625 {
1628 pitem->ShowClearance( aItem->OfKind( tracksOrVias ) );
1629 break;
1630
1632 pitem->ShowClearance( aItem->OfKind( tracksOrVias ) && !aEdit );
1633 break;
1634
1635 case SHOW_WHILE_ROUTING:
1636 pitem->ShowClearance( aItem->OfKind( tracks ) && !aEdit );
1637 break;
1638
1639 default:
1640 pitem->ShowClearance( false );
1641 break;
1642 }
1643 }
1644
1645 if( aIsHeadTrace )
1646 {
1647 pitem->SetIsHeadTrace( true );
1648 pitem->Update( aItem );
1649 }
1650
1651 m_previewItems->Add( pitem );
1653}
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:57
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1591
@ LINE_T
Definition: pns_item.h:64
bool OfKind(int aKindMask) const
Return true if the item's type matches the mask aKindMask.
Definition: pns_item.h:140
bool IsVirtual() const
Definition: pns_item.h:240
void SetClearance(int aClearance)
void SetIsHeadTrace(bool aIsHead)
void Update(const PNS::ITEM *aItem)
void ShowClearance(bool aEnabled)
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:144
APP_SETTINGS_BASE * GetSettings() const
Definition: tool_manager.h:294
@ SHOW_WITH_VIA_WHILE_ROUTING_OR_DRAGGING
@ SHOW_WHILE_ROUTING
@ SHOW_WITH_VIA_ALWAYS
@ SHOW_WITH_VIA_WHILE_ROUTING

References KIGFX::VIEW_GROUP::Add(), PNS::ITEM::ARC_T, TOOL_BASE::GetManager(), TOOL_MANAGER::GetSettings(), PNS::ITEM::IsVirtual(), PNS::ITEM::LINE_T, m_previewItems, m_tool, m_view, PNS::ITEM::OfKind(), PNS::ITEM::SEGMENT_T, ROUTER_PREVIEW_ITEM::SetClearance(), ROUTER_PREVIEW_ITEM::SetIsHeadTrace(), SHOW_WHILE_ROUTING, SHOW_WITH_VIA_ALWAYS, SHOW_WITH_VIA_WHILE_ROUTING, SHOW_WITH_VIA_WHILE_ROUTING_OR_DRAGGING, ROUTER_PREVIEW_ITEM::ShowClearance(), ROUTER_PREVIEW_ITEM::Update(), KIGFX::VIEW::Update(), and PNS::ITEM::VIA_T.

◆ DisplayRatline()

void PNS_KICAD_IFACE::DisplayRatline ( const SHAPE_LINE_CHAIN aRatline,
int  aNetCode 
)
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1656 of file pns_kicad_iface.cpp.

1657{
1658 ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aRatline, m_view );
1659
1660 KIGFX::RENDER_SETTINGS* renderSettings = m_view->GetPainter()->GetSettings();
1661 KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( renderSettings );
1662 bool colorByNet = rs->GetNetColorMode() != NET_COLOR_MODE::OFF;
1663 COLOR4D defaultColor = rs->GetColor( nullptr, LAYER_RATSNEST );
1664 COLOR4D color = defaultColor;
1665
1666 std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_board->GetConnectivity();
1667 std::set<int> highlightedNets = rs->GetHighlightNetCodes();
1668 std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
1669 std::map<wxString, KIGFX::COLOR4D>& ncColors = rs->GetNetclassColorMap();
1670 const std::map<int, wxString>& ncMap = connectivity->GetNetclassMap();
1671
1672 if( colorByNet && netColors.count( aNetCode ) )
1673 color = netColors.at( aNetCode );
1674 else if( colorByNet && ncMap.count( aNetCode ) && ncColors.count( ncMap.at( aNetCode ) ) )
1675 color = ncColors.at( ncMap.at( aNetCode ) );
1676 else
1677 color = defaultColor;
1678
1679 if( color == COLOR4D::UNSPECIFIED )
1680 color = defaultColor;
1681
1682 pitem->SetColor( color.Brightened( 0.5 ).WithAlpha( std::min( 1.0, color.a + 0.4 ) ) );
1683
1684 m_previewItems->Add( pitem );
1686}
int color
Definition: DXF_plotter.cpp:57
@ OFF
Net (and netclass) colors are not shown.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:424
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition: pcb_painter.h:72
NET_COLOR_MODE GetNetColorMode() const
Definition: pcb_painter.h:111
COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:116
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:114
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const std::set< int > & GetHighlightNetCodes() const
Return the netcode of currently highlighted net.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
void SetColor(const KIGFX::COLOR4D &aColor)
@ LAYER_RATSNEST
Definition: layer_ids.h:204

References KIGFX::VIEW_GROUP::Add(), color, KIGFX::PCB_RENDER_SETTINGS::GetColor(), BOARD::GetConnectivity(), KIGFX::RENDER_SETTINGS::GetHighlightNetCodes(), KIGFX::PCB_RENDER_SETTINGS::GetNetclassColorMap(), KIGFX::PCB_RENDER_SETTINGS::GetNetColorMap(), KIGFX::PCB_RENDER_SETTINGS::GetNetColorMode(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), LAYER_RATSNEST, PNS_KICAD_IFACE_BASE::m_board, m_previewItems, m_view, OFF, ROUTER_PREVIEW_ITEM::SetColor(), and KIGFX::VIEW::Update().

◆ EraseView()

void PNS_KICAD_IFACE::EraseView ( )
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1583 of file pns_kicad_iface.cpp.

1584{
1585 for( auto item : m_hiddenItems )
1586 m_view->SetVisible( item, true );
1587
1588 m_hiddenItems.clear();
1589
1590 if( m_previewItems )
1591 {
1594 }
1595
1596 if( m_debugDecorator )
1598}
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1529
std::unordered_set< BOARD_ITEM * > m_hiddenItems

References PNS::DEBUG_DECORATOR::Clear(), KIGFX::VIEW_GROUP::FreeItems(), PNS_KICAD_IFACE_BASE::m_debugDecorator, m_hiddenItems, m_previewItems, m_view, KIGFX::VIEW::SetVisible(), and KIGFX::VIEW::Update().

Referenced by Commit().

◆ GetBoard()

BOARD * PNS_KICAD_IFACE_BASE::GetBoard ( ) const
inlineinherited

Definition at line 79 of file pns_kicad_iface.h.

79{ return m_board; }

References PNS_KICAD_IFACE_BASE::m_board.

Referenced by ROUTER_TOOL::saveRouterDebugLog().

◆ GetDebugDecorator()

PNS::DEBUG_DECORATOR * PNS_KICAD_IFACE_BASE::GetDebugDecorator ( )
overridevirtualinherited

Implements PNS::ROUTER_IFACE.

Definition at line 1024 of file pns_kicad_iface.cpp.

1025{
1026 return m_debugDecorator;
1027}

References PNS_KICAD_IFACE_BASE::m_debugDecorator.

◆ GetRuleResolver()

PNS::RULE_RESOLVER * PNS_KICAD_IFACE_BASE::GetRuleResolver ( )
overridevirtualinherited

Implements PNS::ROUTER_IFACE.

Definition at line 1942 of file pns_kicad_iface.cpp.

1943{
1944 return m_ruleResolver;
1945}

References PNS_KICAD_IFACE_BASE::m_ruleResolver.

Referenced by ROUTER_TOOL::UpdateMessagePanel().

◆ GetUnits()

EDA_UNITS PNS_KICAD_IFACE::GetUnits ( ) const
overridevirtual

◆ GetWorld()

virtual PNS::NODE * PNS_KICAD_IFACE_BASE::GetWorld ( ) const
inlineoverridevirtualinherited

Implements PNS::ROUTER_IFACE.

Definition at line 77 of file pns_kicad_iface.h.

77{ return m_world; };

References PNS_KICAD_IFACE_BASE::m_world.

◆ HideItem()

void PNS_KICAD_IFACE::HideItem ( PNS::ITEM aItem)
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1689 of file pns_kicad_iface.cpp.

1690{
1691 BOARD_ITEM* parent = aItem->Parent();
1692
1693 if( parent )
1694 {
1695 if( m_view->IsVisible( parent ) )
1696 m_hiddenItems.insert( parent );
1697
1698 m_view->SetVisible( parent, false );
1699 m_view->Update( parent, KIGFX::APPEARANCE );
1700 }
1701}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1569
@ APPEARANCE
Visibility flag has changed.
Definition: view_item.h:47

References KIGFX::APPEARANCE, KIGFX::VIEW::IsVisible(), m_hiddenItems, m_view, PNS::ITEM::Parent(), KIGFX::VIEW::SetVisible(), and KIGFX::VIEW::Update().

◆ ImportSizes()

bool PNS_KICAD_IFACE_BASE::ImportSizes ( PNS::SIZES_SETTINGS aSizes,
PNS::ITEM aStartItem,
int  aNet 
)
overridevirtualinherited

Implements PNS::ROUTER_IFACE.

Definition at line 590 of file pns_kicad_iface.cpp.

592{
594 PNS::CONSTRAINT constraint;
595
596 if( aStartItem && m_startLayer < 0 )
597 m_startLayer = aStartItem->Layer();
598
599 aSizes.SetMinClearance( bds.m_MinClearance );
600 aSizes.SetClearanceSource( _( "board minimum clearance" ) );
601
603 m_startLayer, &constraint ) )
604 {
605 if( constraint.m_Value.Min() > bds.m_MinClearance )
606 {
607 aSizes.SetMinClearance( constraint.m_Value.Min() );
608 aSizes.SetClearanceSource( constraint.m_RuleName );
609 }
610 }
611
612 int trackWidth = bds.m_TrackMinWidth;
613 bool found = false;
614 aSizes.SetWidthSource( _( "board minimum track width" ) );
615
616 if( bds.m_UseConnectedTrackWidth && !bds.m_TempOverrideTrackWidth && aStartItem != nullptr )
617 {
618 found = inheritTrackWidth( aStartItem, &trackWidth );
619
620 if( found )
621 aSizes.SetWidthSource( _( "existing track" ) );
622 }
623
624 if( !found && bds.UseNetClassTrack() && aStartItem )
625 {
627 m_startLayer, &constraint ) )
628 {
629 trackWidth = std::max( trackWidth, constraint.m_Value.Opt() );
630 found = true;
631
632 if( trackWidth == constraint.m_Value.Opt() )
633 aSizes.SetWidthSource( constraint.m_RuleName );
634 }
635 }
636
637 if( !found )
638 {
639 trackWidth = std::max( trackWidth, bds.GetCurrentTrackWidth() );
640
641 if( bds.UseNetClassTrack() )
642 aSizes.SetWidthSource( _( "netclass 'Default'" ) );
643 else if( trackWidth == bds.GetCurrentTrackWidth() )
644 aSizes.SetWidthSource( _( "user choice" ) );
645 }
646
647 aSizes.SetTrackWidth( trackWidth );
649
650 int viaDiameter = bds.m_ViasMinSize;
651 int viaDrill = bds.m_MinThroughDrill;
652
653 if( bds.UseNetClassVia() && aStartItem ) // netclass value
654 {
656 nullptr, m_startLayer, &constraint ) )
657 {
658 viaDiameter = std::max( viaDiameter, constraint.m_Value.Opt() );
659 }
660
662 nullptr, m_startLayer, &constraint ) )
663 {
664 viaDrill = std::max( viaDrill, constraint.m_Value.Opt() );
665 }
666 }
667 else
668 {
669 viaDiameter = bds.GetCurrentViaSize();
670 viaDrill = bds.GetCurrentViaDrill();
671 }
672
673 aSizes.SetViaDiameter( viaDiameter );
674 aSizes.SetViaDrill( viaDrill );
675
676 int diffPairWidth = bds.m_TrackMinWidth;
677 int diffPairGap = bds.m_MinClearance;
678 int diffPairViaGap = bds.m_MinClearance;
679
680 aSizes.SetDiffPairWidthSource( _( "board minimum track width" ) );
681 aSizes.SetDiffPairGapSource( _( "board minimum clearance" ) );
682
683 found = false;
684
685 // First try to pick up diff pair width from starting track, if enabled
686 if( bds.m_UseConnectedTrackWidth && aStartItem )
687 found = inheritTrackWidth( aStartItem, &diffPairWidth );
688
689 // Next, pick up gap from netclass, and width also if we didn't get a starting width above
690 if( bds.UseNetClassDiffPair() && aStartItem )
691 {
693 nullptr, m_startLayer, &constraint ) )
694 {
695 diffPairWidth = std::max( diffPairWidth, constraint.m_Value.Opt() );
696
697 if( diffPairWidth == constraint.m_Value.Opt() )
698 aSizes.SetDiffPairWidthSource( constraint.m_RuleName );
699 }
700
702 nullptr, m_startLayer, &constraint ) )
703 {
704 diffPairGap = std::max( diffPairGap, constraint.m_Value.Opt() );
705 diffPairViaGap = std::max( diffPairViaGap, constraint.m_Value.Opt() );
706
707 if( diffPairGap == constraint.m_Value.Opt() )
708 aSizes.SetDiffPairGapSource( constraint.m_RuleName );
709 }
710 }
711 else
712 {
713 diffPairWidth = bds.GetCurrentDiffPairWidth();
714 diffPairGap = bds.GetCurrentDiffPairGap();
715 diffPairViaGap = bds.GetCurrentDiffPairViaGap();
716
717 aSizes.SetDiffPairWidthSource( _( "user choice" ) );
718 aSizes.SetDiffPairGapSource( _( "user choice" ) );
719 }
720
721 aSizes.SetDiffPairWidth( diffPairWidth );
722 aSizes.SetDiffPairGap( diffPairGap );
723 aSizes.SetDiffPairViaGap( diffPairViaGap );
724 aSizes.SetDiffPairViaGapSameAsTraceGap( false );
725
726 int holeToHoleMin = bds.m_HoleToHoleMin;
727 PNS::VIA dummyVia;
728
730 &dummyVia, UNDEFINED_LAYER, &constraint ) )
731 {
732 holeToHoleMin = constraint.m_Value.Min();
733 }
734
735 aSizes.SetHoleToHole( holeToHoleMin );
736
737 return true;
738}
Container for design settings for a BOARD object.
bool UseNetClassVia() const
Return true if netclass values should be used to obtain appropriate via size.
bool UseNetClassTrack() const
Return true if netclass values should be used to obtain appropriate track width.
bool UseNetClassDiffPair() const
Return true if netclass values should be used to obtain appropriate diff pair dimensions.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:682
T Min() const
Definition: minoptmax.h:33
T Opt() const
Definition: minoptmax.h:35
virtual int Layer() const
Definition: pns_item.h:160
void SetTrackWidth(int aWidth)
void SetDiffPairViaGapSameAsTraceGap(bool aEnable)
void SetDiffPairWidth(int aWidth)
void SetDiffPairWidthSource(const wxString &aSource)
void SetDiffPairGapSource(const wxString &aSource)
void SetDiffPairGap(int aGap)
void SetHoleToHole(int aHoleToHole)
void SetViaDrill(int aDrill)
void SetDiffPairViaGap(int aGap)
void SetMinClearance(int aClearance)
void SetViaDiameter(int aDiameter)
void SetClearanceSource(const wxString &aSource)
void SetWidthSource(const wxString &aSource)
void SetTrackWidthIsExplicit(bool aIsExplicit)
bool inheritTrackWidth(PNS::ITEM *aItem, int *aInheritedWidth)
virtual bool QueryConstraint(PNS::CONSTRAINT_TYPE aType, const PNS::ITEM *aItemA, const PNS::ITEM *aItemB, int aLayer, PNS::CONSTRAINT *aConstraint) override
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
wxString m_RuleName
Definition: pns_node.h:72
MINOPTMAX< int > m_Value
Definition: pns_node.h:70

References _, PNS::CT_CLEARANCE, PNS::CT_DIFF_PAIR_GAP, PNS::CT_HOLE_TO_HOLE, PNS::CT_VIA_DIAMETER, PNS::CT_VIA_HOLE, PNS::CT_WIDTH, BOARD_DESIGN_SETTINGS::GetCurrentDiffPairGap(), BOARD_DESIGN_SETTINGS::GetCurrentDiffPairViaGap(), BOARD_DESIGN_SETTINGS::GetCurrentDiffPairWidth(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetCurrentViaDrill(), BOARD_DESIGN_SETTINGS::GetCurrentViaSize(), BOARD::GetDesignSettings(), PNS_KICAD_IFACE_BASE::inheritTrackWidth(), PNS::ITEM::Layer(), PNS_KICAD_IFACE_BASE::m_board, BOARD_DESIGN_SETTINGS::m_HoleToHoleMin, BOARD_DESIGN_SETTINGS::m_MinClearance, BOARD_DESIGN_SETTINGS::m_MinThroughDrill, PNS::CONSTRAINT::m_RuleName, PNS_KICAD_IFACE_BASE::m_ruleResolver, PNS_KICAD_IFACE_BASE::m_startLayer, BOARD_DESIGN_SETTINGS::m_TempOverrideTrackWidth, BOARD_DESIGN_SETTINGS::m_TrackMinWidth, BOARD_DESIGN_SETTINGS::m_UseConnectedTrackWidth, PNS::CONSTRAINT::m_Value, BOARD_DESIGN_SETTINGS::m_ViasMinSize, MINOPTMAX< T >::Min(), MINOPTMAX< T >::Opt(), PNS_PCBNEW_RULE_RESOLVER::QueryConstraint(), PNS::SIZES_SETTINGS::SetClearanceSource(), PNS::SIZES_SETTINGS::SetDiffPairGap(), PNS::SIZES_SETTINGS::SetDiffPairGapSource(), PNS::SIZES_SETTINGS::SetDiffPairViaGap(), PNS::SIZES_SETTINGS::SetDiffPairViaGapSameAsTraceGap(), PNS::SIZES_SETTINGS::SetDiffPairWidth(), PNS::SIZES_SETTINGS::SetDiffPairWidthSource(), PNS::SIZES_SETTINGS::SetHoleToHole(), PNS::SIZES_SETTINGS::SetMinClearance(), PNS::SIZES_SETTINGS::SetTrackWidth(), PNS::SIZES_SETTINGS::SetTrackWidthIsExplicit(), PNS::SIZES_SETTINGS::SetViaDiameter(), PNS::SIZES_SETTINGS::SetViaDrill(), PNS::SIZES_SETTINGS::SetWidthSource(), UNDEFINED_LAYER, BOARD_DESIGN_SETTINGS::UseNetClassDiffPair(), BOARD_DESIGN_SETTINGS::UseNetClassTrack(), and BOARD_DESIGN_SETTINGS::UseNetClassVia().

Referenced by ROUTER_TOOL::onTrackViaSizeChanged(), and ROUTER_TOOL::prepareInteractive().

◆ inheritTrackWidth()

bool PNS_KICAD_IFACE_BASE::inheritTrackWidth ( PNS::ITEM aItem,
int *  aInheritedWidth 
)
protectedinherited

Definition at line 527 of file pns_kicad_iface.cpp.

528{
529 VECTOR2I p;
530
531 assert( aItem->Owner() != nullptr );
532
533 auto tryGetTrackWidth =
534 []( PNS::ITEM* aPnsItem ) -> int
535 {
536 switch( aPnsItem->Kind() )
537 {
538 case PNS::ITEM::SEGMENT_T: return static_cast<PNS::SEGMENT*>( aPnsItem )->Width();
539 case PNS::ITEM::ARC_T: return static_cast<PNS::ARC*>( aPnsItem )->Width();
540 default: return -1;
541 }
542 };
543
544 int itemTrackWidth = tryGetTrackWidth( aItem );
545
546 if( itemTrackWidth > 0 )
547 {
548 *aInheritedWidth = itemTrackWidth;
549 return true;
550 }
551
552 switch( aItem->Kind() )
553 {
554 case PNS::ITEM::VIA_T:
555 p = static_cast<PNS::VIA*>( aItem )->Pos();
556 break;
557
559 p = static_cast<PNS::SOLID*>( aItem )->Pos();
560 break;
561
562 default:
563 return false;
564 }
565
566 PNS::JOINT* jt = static_cast<PNS::NODE*>( aItem->Owner() )->FindJoint( p, aItem );
567
568 assert( jt != nullptr );
569
570 int mval = INT_MAX;
571
572 PNS::ITEM_SET linkedSegs = jt->Links();
574
575 for( PNS::ITEM* item : linkedSegs.Items() )
576 {
577 int w = tryGetTrackWidth( item );
578 assert( w > 0 );
579 mval = std::min( w, mval );
580 }
581
582 if( mval == INT_MAX )
583 return false;
584
585 *aInheritedWidth = mval;
586 return true;
587}
ITEM_SET & ExcludeItem(const ITEM *aItem)
ITEM_SET & FilterKinds(int aKindMask, bool aInvert=false)
Definition: pns_itemset.cpp:68
ENTRIES & Items()
Definition: pns_itemset.h:135
Base class for PNS router board items.
Definition: pns_item.h:56
NODE * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:173
A 2D point on a given set of layers and belonging to a certain net, that links together a number of b...
Definition: pns_joint.h:43
ITEM_SET & Links()
Definition: pns_joint.h:251
Keep the router "world" - i.e.
Definition: pns_node.h:156

References PNS::ITEM::ARC_T, PNS::ITEM_SET::ExcludeItem(), PNS::ITEM_SET::FilterKinds(), PNS::ITEM_SET::Items(), PNS::ITEM::Kind(), PNS::JOINT::Links(), PNS::ITEM::Owner(), PNS::ITEM::SEGMENT_T, PNS::ITEM::SOLID_T, and PNS::ITEM::VIA_T.

Referenced by PNS_KICAD_IFACE_BASE::ImportSizes().

◆ IsAnyLayerVisible()

bool PNS_KICAD_IFACE::IsAnyLayerVisible ( const LAYER_RANGE aLayer) const
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1402 of file pns_kicad_iface.cpp.

1403{
1404 if( !m_view )
1405 return false;
1406
1407 for( int i = aLayer.Start(); i <= aLayer.End(); i++ )
1408 {
1409 if( m_view->IsLayerVisible( i ) )
1410 return true;
1411 }
1412
1413 return false;
1414}
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:410
int End() const
Definition: pns_layerset.h:87

References LAYER_RANGE::End(), KIGFX::VIEW::IsLayerVisible(), m_view, and LAYER_RANGE::Start().

Referenced by PNS::TOOL_BASE::pickSingleItem().

◆ IsFlashedOnLayer()

bool PNS_KICAD_IFACE_BASE::IsFlashedOnLayer ( const PNS::ITEM aItem,
int  aLayer 
) const
overridevirtualinherited

Default is all layers

Implements PNS::ROUTER_IFACE.

Definition at line 1417 of file pns_kicad_iface.cpp.

1418{
1420 if( aLayer < 0 )
1421 return true;
1422
1423 if( aItem->Parent() )
1424 {
1425 switch( aItem->Parent()->Type() )
1426 {
1427 case PCB_VIA_T:
1428 {
1429 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem->Parent() );
1430
1431 return via->FlashLayer( ToLAYER_ID( aLayer ) );
1432 }
1433
1434 case PCB_PAD_T:
1435 {
1436 const PAD* pad = static_cast<const PAD*>( aItem->Parent() );
1437
1438 return pad->FlashLayer( ToLAYER_ID( aLayer ) );
1439 }
1440
1441 default:
1442 break;
1443 }
1444 }
1445
1446 return aItem->Layers().Overlaps( aLayer );
1447}
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87

References PNS::ITEM::Layers(), LAYER_RANGE::Overlaps(), pad, PNS::ITEM::Parent(), PCB_PAD_T, PCB_VIA_T, ToLAYER_ID(), EDA_ITEM::Type(), and via.

◆ IsItemVisible()

bool PNS_KICAD_IFACE::IsItemVisible ( const PNS::ITEM aItem) const
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1450 of file pns_kicad_iface.cpp.

1451{
1452 // by default, all items are visible (new ones created by the router have parent == NULL
1453 // as they have not been committed yet to the BOARD)
1454 if( !m_view || !aItem->Parent() )
1455 return true;
1456
1457 BOARD_ITEM* item = aItem->Parent();
1458 bool isOnVisibleLayer = true;
1459 RENDER_SETTINGS* settings = m_view->GetPainter()->GetSettings();
1460
1461 if( settings->GetHighContrast() )
1462 isOnVisibleLayer = item->IsOnLayer( settings->GetPrimaryHighContrastLayer() );
1463
1464 if( m_view->IsVisible( item ) && isOnVisibleLayer )
1465 {
1466 for( PCB_LAYER_ID layer : item->GetLayerSet().Seq() )
1467 {
1468 if( item->ViewGetLOD( layer, m_view ) < m_view->GetScale() )
1469 return true;
1470 }
1471 }
1472
1473 // Items hidden in the router are not hidden on the board
1474 if( m_hiddenItems.find( item ) != m_hiddenItems.end() )
1475 return true;
1476
1477 return false;
1478}
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:245
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:185
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
bool GetHighContrast() const
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
Definition: view_item.h:132
double GetScale() const
Definition: view.h:269
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59

References KIGFX::RENDER_SETTINGS::GetHighContrast(), BOARD_ITEM::GetLayerSet(), KIGFX::VIEW::GetPainter(), KIGFX::RENDER_SETTINGS::GetPrimaryHighContrastLayer(), KIGFX::VIEW::GetScale(), KIGFX::PAINTER::GetSettings(), BOARD_ITEM::IsOnLayer(), KIGFX::VIEW::IsVisible(), m_hiddenItems, m_view, PNS::ITEM::Parent(), LSET::Seq(), and KIGFX::VIEW_ITEM::ViewGetLOD().

Referenced by PNS::TOOL_BASE::snapToItem().

◆ RemoveItem()

void PNS_KICAD_IFACE::RemoveItem ( PNS::ITEM aItem)
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1709 of file pns_kicad_iface.cpp.

1710{
1711 BOARD_ITEM* parent = aItem->Parent();
1712
1713 if( aItem->OfKind( PNS::ITEM::SOLID_T ) )
1714 {
1715 PAD* pad = static_cast<PAD*>( parent );
1716 VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1717
1718 m_fpOffsets[ pad ].p_old = pos;
1719 return;
1720 }
1721
1722 if( parent )
1723 {
1724 m_commit->Remove( parent );
1725 }
1726}

References m_commit, m_fpOffsets, PNS::ITEM::OfKind(), pad, PNS::ITEM::Parent(), and PNS::ITEM::SOLID_T.

◆ SetBoard()

void PNS_KICAD_IFACE_BASE::SetBoard ( BOARD aBoard)
inherited

Definition at line 1395 of file pns_kicad_iface.cpp.

1396{
1397 m_board = aBoard;
1398 wxLogTrace( wxT( "PNS" ), wxT( "m_board = %p" ), m_board );
1399}

References PNS_KICAD_IFACE_BASE::m_board.

Referenced by PNS::TOOL_BASE::Reset().

◆ SetCommitFlags()

void PNS_KICAD_IFACE::SetCommitFlags ( int  aCommitFlags)
inline

Definition at line 129 of file pns_kicad_iface.h.

129{ m_commitFlags = aCommitFlags; }

References m_commitFlags.

Referenced by ROUTER_TOOL::performRouting(), and ROUTER_TOOL::RouteSelected().

◆ SetDebugDecorator()

void PNS_KICAD_IFACE_BASE::SetDebugDecorator ( PNS::DEBUG_DECORATOR aDec)
inherited

Definition at line 1601 of file pns_kicad_iface.cpp.

1602{
1603 m_debugDecorator = aDec;
1604}

References PNS_KICAD_IFACE_BASE::m_debugDecorator.

◆ SetHostTool()

void PNS_KICAD_IFACE::SetHostTool ( PCB_TOOL_BASE aTool)

Definition at line 1948 of file pns_kicad_iface.cpp.

1949{
1950 m_tool = aTool;
1951 m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1952}

References m_commit, and m_tool.

Referenced by PNS::TOOL_BASE::Reset().

◆ SetStartLayer()

void PNS_KICAD_IFACE_BASE::SetStartLayer ( int  aLayer)
inlineinherited

Definition at line 75 of file pns_kicad_iface.h.

75{ m_startLayer = aLayer; }

References PNS_KICAD_IFACE_BASE::m_startLayer.

Referenced by ROUTER_TOOL::prepareInteractive().

◆ SetView()

void PNS_KICAD_IFACE::SetView ( KIGFX::VIEW aView)

Definition at line 1907 of file pns_kicad_iface.cpp.

1908{
1909 wxLogTrace( wxT( "PNS" ), wxT( "SetView %p" ), aView );
1910
1911 if( m_previewItems )
1912 {
1914 delete m_previewItems;
1915 }
1916
1917 m_view = aView;
1920
1921 if(m_view)
1923
1924 delete m_debugDecorator;
1925
1926 auto dec = new PNS_PCBNEW_DEBUG_DECORATOR();
1927 m_debugDecorator = dec;
1928
1929 dec->SetDebugEnabled( ADVANCED_CFG::GetCfg().m_ShowRouterDebugGraphics );
1930
1931 if( ADVANCED_CFG::GetCfg().m_ShowRouterDebugGraphics )
1932 dec->SetView( m_view );
1933}
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition: view_group.h:47
virtual void SetLayer(int aLayer)
Set layer used to draw the group.
Definition: view_group.h:98
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
void SetDebugEnabled(bool aEnabled)
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:219

References KIGFX::VIEW::Add(), KIGFX::VIEW_GROUP::FreeItems(), ADVANCED_CFG::GetCfg(), LAYER_SELECT_OVERLAY, PNS_KICAD_IFACE_BASE::m_debugDecorator, m_previewItems, m_view, PNS::DEBUG_DECORATOR::SetDebugEnabled(), and KIGFX::VIEW_GROUP::SetLayer().

Referenced by PNS::TOOL_BASE::Reset().

◆ StackupHeight()

int PNS_KICAD_IFACE_BASE::StackupHeight ( int  aFirstLayer,
int  aSecondLayer 
) const
overridevirtualinherited

Implements PNS::ROUTER_IFACE.

Definition at line 741 of file pns_kicad_iface.cpp.

742{
744 return 0;
745
747
748 return stackup.GetLayerDistance( ToLAYER_ID( aFirstLayer ), ToLAYER_ID( aSecondLayer ) );
749}
BOARD_STACKUP & GetStackupDescriptor()
bool m_UseHeightForLengthCalcs
Enable inclusion of stackup height in track length measurements and length tuning.
Manage layers needed to make a physical board.
int GetLayerDistance(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Calculate the distance (height) between the two given copper layers.

References BOARD::GetDesignSettings(), BOARD_STACKUP::GetLayerDistance(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), PNS_KICAD_IFACE_BASE::m_board, BOARD_DESIGN_SETTINGS::m_UseHeightForLengthCalcs, and ToLAYER_ID().

◆ syncArc()

std::unique_ptr< PNS::ARC > PNS_KICAD_IFACE_BASE::syncArc ( PCB_ARC aArc)
protectedinherited

Definition at line 1175 of file pns_kicad_iface.cpp.

1176{
1177 auto arc = std::make_unique<PNS::ARC>(
1178 SHAPE_ARC( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), aArc->GetWidth() ),
1179 aArc->GetNetCode() );
1180
1181 arc->SetLayers( LAYER_RANGE( aArc->GetLayer() ) );
1182 arc->SetParent( aArc );
1183
1184 if( aArc->IsLocked() )
1185 arc->Mark( PNS::MK_LOCKED );
1186
1187 return arc;
1188}
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:180
virtual bool IsLocked() const
Definition: board_item.cpp:71
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
const VECTOR2I & GetMid() const
Definition: pcb_track.h:312
int GetWidth() const
Definition: pcb_track.h:107
const VECTOR2I & GetStart() const
Definition: pcb_track.h:113
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:110
@ MK_LOCKED
Definition: pns_item.h:43

References PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayer(), PCB_ARC::GetMid(), BOARD_CONNECTED_ITEM::GetNetCode(), PCB_TRACK::GetStart(), PCB_TRACK::GetWidth(), BOARD_ITEM::IsLocked(), and PNS::MK_LOCKED.

Referenced by PNS_KICAD_IFACE_BASE::SyncWorld().

◆ syncGraphicalItem()

bool PNS_KICAD_IFACE_BASE::syncGraphicalItem ( PNS::NODE aWorld,
PCB_SHAPE aItem 
)
protectedinherited

Definition at line 1348 of file pns_kicad_iface.cpp.

1349{
1350 if( aItem->GetLayer() == Edge_Cuts
1351 || aItem->GetLayer() == Margin
1352 || IsCopperLayer( aItem->GetLayer() ) )
1353 {
1354 std::vector<SHAPE*> shapes = aItem->MakeEffectiveShapes();
1355
1356 for( SHAPE* shape : shapes )
1357 {
1358 std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
1359
1360 if( aItem->GetLayer() == Edge_Cuts || aItem->GetLayer() == Margin )
1361 solid->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
1362 else
1363 solid->SetLayer( aItem->GetLayer() );
1364
1365 if( aItem->GetLayer() == Edge_Cuts )
1366 {
1367 switch( shape->Type() )
1368 {
1369 case SH_SEGMENT: static_cast<SHAPE_SEGMENT*>( shape )->SetWidth( 0 ); break;
1370 case SH_ARC: static_cast<SHAPE_ARC*>( shape )->SetWidth( 0 ); break;
1371 case SH_LINE_CHAIN: static_cast<SHAPE_LINE_CHAIN*>( shape )->SetWidth( 0 ); break;
1372 default: /* remaining shapes don't have width */ break;
1373 }
1374 }
1375
1376 solid->SetNet( -1 );
1377 solid->SetParent( aItem );
1378 solid->SetShape( shape ); // takes ownership
1379
1380 if( shapes.size() > 1 )
1381 solid->SetIsCompoundShapePrimitive();
1382
1383 solid->SetRoutable( false );
1384
1385 aWorld->Add( std::move( solid ) );
1386 }
1387
1388 return true;
1389 }
1390
1391 return false;
1392}
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.h:289
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Add an item to the current node.
Definition: pns_node.cpp:664
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
An abstract shape on 2D plane.
Definition: shape.h:123
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:825
@ Edge_Cuts
Definition: layer_ids.h:113
@ B_Cu
Definition: layer_ids.h:95
@ Margin
Definition: layer_ids.h:114
@ F_Cu
Definition: layer_ids.h:64
void SetWidth(const wxString &aStr, const wxString &aDefaultMeasurementUnit, int *aWidth, const wxString &aActualConversion)
@ SH_SEGMENT
line segment
Definition: shape.h:45
@ SH_ARC
circular arc
Definition: shape.h:51
@ SH_LINE_CHAIN
line chain (polyline)
Definition: shape.h:46

References PNS::NODE::Add(), B_Cu, Edge_Cuts, F_Cu, BOARD_ITEM::GetLayer(), IsCopperLayer(), EDA_SHAPE::MakeEffectiveShapes(), Margin, PCAD2KICAD::SetWidth(), SH_ARC, SH_LINE_CHAIN, and SH_SEGMENT.

Referenced by PNS_KICAD_IFACE_BASE::SyncWorld().

◆ syncPad()

std::unique_ptr< PNS::SOLID > PNS_KICAD_IFACE_BASE::syncPad ( PAD aPad)
protectedinherited

Definition at line 1067 of file pns_kicad_iface.cpp.

1068{
1069 LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 );
1070
1071 // ignore non-copper pads except for those with holes
1072 if( ( aPad->GetLayerSet() & LSET::AllCuMask() ).none() && aPad->GetDrillSize().x == 0 )
1073 return nullptr;
1074
1075 switch( aPad->GetAttribute() )
1076 {
1077 case PAD_ATTRIB::PTH:
1078 case PAD_ATTRIB::NPTH:
1079 break;
1080
1081 case PAD_ATTRIB::CONN:
1082 case PAD_ATTRIB::SMD:
1083 {
1084 LSET lmsk = aPad->GetLayerSet();
1085 bool is_copper = false;
1086
1087 for( int i = 0; i < MAX_CU_LAYERS; i++ )
1088 {
1089 if( lmsk[i] )
1090 {
1091 is_copper = true;
1092
1093 if( aPad->GetAttribute() != PAD_ATTRIB::NPTH )
1094 layers = LAYER_RANGE( i );
1095
1096 break;
1097 }
1098 }
1099
1100 if( !is_copper )
1101 return nullptr;
1102
1103 break;
1104 }
1105
1106 default:
1107 wxLogTrace( wxT( "PNS" ), wxT( "unsupported pad type 0x%x" ), aPad->GetAttribute() );
1108 return nullptr;
1109 }
1110
1111 std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
1112
1113 if( aPad->GetAttribute() == PAD_ATTRIB::NPTH )
1114 solid->SetRoutable( false );
1115
1116 solid->SetLayers( layers );
1117 solid->SetNet( aPad->GetNetCode() );
1118 solid->SetParent( aPad );
1119 solid->SetPadToDie( aPad->GetPadToDieLength() );
1120 solid->SetOrientation( aPad->GetOrientation() );
1121
1122 if( aPad->IsFreePad() )
1123 solid->SetIsFreePad();
1124
1125 VECTOR2I wx_c = aPad->ShapePos();
1126 VECTOR2I offset = aPad->GetOffset();
1127
1128 VECTOR2I c( wx_c.x, wx_c.y );
1129
1130 RotatePoint( offset, aPad->GetOrientation() );
1131
1132 solid->SetPos( VECTOR2I( c.x - offset.x, c.y - offset.y ) );
1133 solid->SetOffset( VECTOR2I( offset.x, offset.y ) );
1134
1135 if( aPad->GetDrillSize().x > 0 )
1136 solid->SetHole( aPad->GetEffectiveHoleShape()->Clone() );
1137
1138 // We generate a single SOLID for a pad, so we have to treat it as ALWAYS_FLASHED and then
1139 // perform layer-specific flashing tests internally.
1140 std::shared_ptr<SHAPE> shape = aPad->GetEffectiveShape( UNDEFINED_LAYER,
1142
1143 if( shape->HasIndexableSubshapes() && shape->GetIndexableSubshapeCount() == 1 )
1144 {
1145 std::vector<const SHAPE*> subshapes;
1146 shape->GetIndexableSubshapes( subshapes );
1147
1148 solid->SetShape( subshapes[0]->Clone() );
1149 }
1150 else
1151 {
1152 solid->SetShape( shape->Clone() );
1153 }
1154
1155 return solid;
1156}
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:773
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pad.h:397
const VECTOR2I & GetDrillSize() const
Definition: pad.h:267
PAD_ATTRIB GetAttribute() const
Definition: pad.h:400
const VECTOR2I & GetOffset() const
Definition: pad.h:274
VECTOR2I ShapePos() const
Definition: pad.cpp:785
bool IsFreePad() const
Definition: pad.cpp:189
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition: pad.h:370
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING flashPTHPads=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pad.cpp:385
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const override
Return a SHAPE_SEGMENT object representing the pad's hole.
Definition: pad.cpp:422
int GetPadToDieLength() const
Definition: pad.h:413
@ ALWAYS_FLASHED
#define MAX_CU_LAYERS
Definition: layer_ids.h:140
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:279
@ NPTH
like PAD_PTH, but not plated
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References LSET::AllCuMask(), ALWAYS_FLASHED, PNS::Clone(), CONN, PAD::GetAttribute(), PAD::GetDrillSize(), PAD::GetEffectiveHoleShape(), PAD::GetEffectiveShape(), PAD::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetCode(), PAD::GetOffset(), PAD::GetOrientation(), PAD::GetPadToDieLength(), PAD::IsFreePad(), MAX_CU_LAYERS, NPTH, PTH, RotatePoint(), PAD::ShapePos(), SMD, UNDEFINED_LAYER, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PNS_KICAD_IFACE_BASE::SyncWorld().

◆ syncTextItem()

bool PNS_KICAD_IFACE_BASE::syncTextItem ( PNS::NODE aWorld,
EDA_TEXT aText,
PCB_LAYER_ID  aLayer 
)
protectedinherited

Definition at line 1287 of file pns_kicad_iface.cpp.

1288{
1289 if( !IsCopperLayer( aLayer ) )
1290 return false;
1291
1292 std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
1293
1294 solid->SetLayer( aLayer );
1295 solid->SetNet( -1 );
1296 solid->SetParent( dynamic_cast<BOARD_ITEM*>( aText ) );
1297
1298 PCB_TEXT* pcb_text = dynamic_cast<PCB_TEXT*>( aText );
1299
1300 if( pcb_text && pcb_text->IsKnockout() )
1301 {
1302 TEXT_ATTRIBUTES attrs = pcb_text->GetAttributes();
1303 SHAPE_POLY_SET buffer;
1304 int margin = attrs.m_StrokeWidth * 1.5
1305 + GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
1306 pcb_text->TransformBoundingBoxToPolygon( &buffer, margin );
1307 // buffer should contain a single rectangular polygon
1308 SHAPE_SIMPLE* rectShape = new SHAPE_SIMPLE;
1309
1310 for( int ii = 0; ii < buffer.Outline(0).PointCount(); ii++ )
1311 {
1312 VECTOR2I point = buffer.Outline(0).CPoint(ii);
1313 rectShape->Append( point );
1314 }
1315
1316 solid->SetShape( rectShape );
1317 }
1318 else
1319 solid->SetShape( aText->GetEffectiveTextShape()->Clone() );
1320
1321 solid->SetRoutable( false );
1322
1323 aWorld->Add( std::move( solid ) );
1324
1325 return true;
1326
1327 /* A coarser (but faster) method:
1328 SHAPE_POLY_SET outline;
1329 SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
1330
1331 aText->TransformBoundingBoxToPolygon( &outline, 0 );
1332
1333 for( auto iter = outline.CIterate( 0 ); iter; iter++ )
1334 shape->Append( *iter );
1335
1336 solid->SetShape( shape );
1337
1338 solid->SetLayer( aLayer );
1339 solid->SetNet( -1 );
1340 solid->SetParent( nullptr );
1341 solid->SetRoutable( false );
1342 aWorld->Add( std::move( solid ) );
1343 return true;
1344 */
1345}
virtual bool IsKnockout() const
Definition: board_item.h:250
void TransformBoundingBoxToPolygon(SHAPE_POLY_SET *aBuffer, int aClearance) const
Convert the text bounding box to a rectangular polygon depending on the text orientation,...
Definition: eda_text.cpp:945
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:172
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, bool aUseTextRotation=true) const
build a list of segments (SHAPE_SEGMENT) to describe a text shape.
Definition: eda_text.cpp:853
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition: shape_simple.h:42
void Append(int aX, int aY)
Append a new point at the end of the polygon.
Definition: shape_simple.h:135
int GetKnockoutTextMargin(const VECTOR2I &aSize, int aThickness)
Returns the margin for knocking out text.
Definition: gr_text.h:97

References PNS::NODE::Add(), SHAPE_SIMPLE::Append(), SHAPE_LINE_CHAIN::CPoint(), EDA_TEXT::GetAttributes(), EDA_TEXT::GetEffectiveTextShape(), GetKnockoutTextMargin(), IsCopperLayer(), BOARD_ITEM::IsKnockout(), TEXT_ATTRIBUTES::m_Size, TEXT_ATTRIBUTES::m_StrokeWidth, SHAPE_POLY_SET::Outline(), and EDA_TEXT::TransformBoundingBoxToPolygon().

Referenced by PNS_KICAD_IFACE_BASE::SyncWorld().

◆ syncTrack()

std::unique_ptr< PNS::SEGMENT > PNS_KICAD_IFACE_BASE::syncTrack ( PCB_TRACK aTrack)
protectedinherited

Definition at line 1159 of file pns_kicad_iface.cpp.

1160{
1161 auto segment = std::make_unique<PNS::SEGMENT>( SEG( aTrack->GetStart(), aTrack->GetEnd() ),
1162 aTrack->GetNetCode() );
1163
1164 segment->SetWidth( aTrack->GetWidth() );
1165 segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) );
1166 segment->SetParent( aTrack );
1167
1168 if( aTrack->IsLocked() )
1169 segment->Mark( PNS::MK_LOCKED );
1170
1171 return segment;
1172}

References PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayer(), BOARD_CONNECTED_ITEM::GetNetCode(), PCB_TRACK::GetStart(), PCB_TRACK::GetWidth(), BOARD_ITEM::IsLocked(), and PNS::MK_LOCKED.

Referenced by PNS_KICAD_IFACE_BASE::SyncWorld().

◆ syncVia()

std::unique_ptr< PNS::VIA > PNS_KICAD_IFACE_BASE::syncVia ( PCB_VIA aVia)
protectedinherited

Definition at line 1191 of file pns_kicad_iface.cpp.

1192{
1193 PCB_LAYER_ID top, bottom;
1194 aVia->LayerPair( &top, &bottom );
1195
1196 auto via = std::make_unique<PNS::VIA>( aVia->GetPosition(),
1197 LAYER_RANGE( aVia->TopLayer(), aVia->BottomLayer() ),
1198 aVia->GetWidth(),
1199 aVia->GetDrillValue(),
1200 aVia->GetNetCode(),
1201 aVia->GetViaType() );
1202
1203 via->SetParent( aVia );
1204
1205 if( aVia->IsLocked() )
1206 via->Mark( PNS::MK_LOCKED );
1207
1208 via->SetIsFree( aVia->GetIsFree() );
1209
1211 via->SetHole( SHAPE_CIRCLE( aVia->GetPosition(),
1212 aVia->GetDrillValue() / 2 ) );
1213
1214 return via;
1215}
bool GetIsFree() const
Checks if the via is a free via (as opposed to one created on a track by the router).
Definition: pcb_track.h:543
PCB_LAYER_ID BottomLayer() const
Definition: pcb_track.cpp:600
VECTOR2I GetPosition() const override
Definition: pcb_track.h:441
PCB_LAYER_ID TopLayer() const
Definition: pcb_track.cpp:594
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
Definition: pcb_track.cpp:222
VIATYPE GetViaType() const
Definition: pcb_track.h:393
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
Definition: pcb_track.cpp:572

References PCB_VIA::BottomLayer(), BOARD::GetDesignSettings(), PCB_VIA::GetDrillValue(), PCB_VIA::GetIsFree(), BOARD_CONNECTED_ITEM::GetNetCode(), PCB_VIA::GetPosition(), PCB_VIA::GetViaType(), PCB_TRACK::GetWidth(), BOARD_ITEM::IsLocked(), PCB_VIA::LayerPair(), PNS_KICAD_IFACE_BASE::m_board, PNS::MK_LOCKED, PCB_VIA::TopLayer(), and via.

Referenced by PNS_KICAD_IFACE_BASE::SyncWorld().

◆ SyncWorld()

void PNS_KICAD_IFACE_BASE::SyncWorld ( PNS::NODE aWorld)
overridevirtualinherited

Implements PNS::ROUTER_IFACE.

Definition at line 1481 of file pns_kicad_iface.cpp.

1482{
1483 if( !m_board )
1484 {
1485 wxLogTrace( wxT( "PNS" ), wxT( "No board attached, aborting sync." ) );
1486 return;
1487 }
1488
1489 int worstClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
1490
1491 m_world = aWorld;
1492
1493 for( BOARD_ITEM* gitem : m_board->Drawings() )
1494 {
1495 if ( gitem->Type() == PCB_SHAPE_T || gitem->Type() == PCB_TEXTBOX_T )
1496 {
1497 syncGraphicalItem( aWorld, static_cast<PCB_SHAPE*>( gitem ) );
1498 }
1499 else if( gitem->Type() == PCB_TEXT_T )
1500 {
1501 syncTextItem( aWorld, static_cast<PCB_TEXT*>( gitem ), gitem->GetLayer() );
1502 }
1503 }
1504
1505 SHAPE_POLY_SET buffer;
1506 SHAPE_POLY_SET* boardOutline = nullptr;
1507
1508 if( m_board->GetBoardPolygonOutlines( buffer ) )
1509 boardOutline = &buffer;
1510
1511 for( ZONE* zone : m_board->Zones() )
1512 {
1513 syncZone( aWorld, zone, boardOutline );
1514 }
1515
1516 for( FOOTPRINT* footprint : m_board->Footprints() )
1517 {
1518 for( PAD* pad : footprint->Pads() )
1519 {
1520 if( std::unique_ptr<PNS::SOLID> solid = syncPad( pad ) )
1521 aWorld->Add( std::move( solid ) );
1522
1523 worstClearance = std::max( worstClearance, pad->GetLocalClearance() );
1524
1525 if( pad->GetProperty() == PAD_PROP::CASTELLATED )
1526 {
1527 std::unique_ptr<SHAPE> hole;
1528 hole.reset( pad->GetEffectiveHoleShape()->Clone() );
1529 aWorld->AddEdgeExclusion( std::move( hole ) );
1530 }
1531 }
1532
1533 syncTextItem( aWorld, &footprint->Reference(), footprint->Reference().GetLayer() );
1534 syncTextItem( aWorld, &footprint->Value(), footprint->Value().GetLayer() );
1535
1536 for( FP_ZONE* zone : footprint->Zones() )
1537 syncZone( aWorld, zone, boardOutline );
1538
1539 for( BOARD_ITEM* mgitem : footprint->GraphicalItems() )
1540 {
1541 if( mgitem->Type() == PCB_FP_SHAPE_T || mgitem->Type() == PCB_FP_TEXTBOX_T )
1542 {
1543 syncGraphicalItem( aWorld, static_cast<PCB_SHAPE*>( mgitem ) );
1544 }
1545 else if( mgitem->Type() == PCB_FP_TEXT_T )
1546 {
1547 syncTextItem( aWorld, static_cast<FP_TEXT*>( mgitem ), mgitem->GetLayer() );
1548 }
1549 }
1550 }
1551
1552 for( PCB_TRACK* t : m_board->Tracks() )
1553 {
1554 KICAD_T type = t->Type();
1555
1556 if( type == PCB_TRACE_T )
1557 {
1558 if( auto segment = syncTrack( t ) )
1559 aWorld->Add( std::move( segment ) );
1560 }
1561 else if( type == PCB_ARC_T )
1562 {
1563 if( auto arc = syncArc( static_cast<PCB_ARC*>( t ) ) )
1564 aWorld->Add( std::move( arc ) );
1565 }
1566 else if( type == PCB_VIA_T )
1567 {
1568 if( auto via = syncVia( static_cast<PCB_VIA*>( t ) ) )
1569 aWorld->Add( std::move( via ) );
1570 }
1571 }
1572
1573 // NB: if this were ever to become a long-lived object we would need to dirty its
1574 // clearance cache here....
1575 delete m_ruleResolver;
1577
1579 aWorld->SetMaxClearance( worstClearance + m_ruleResolver->ClearanceEpsilon() );
1580}
ZONES & Zones()
Definition: board.h:313
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:1950
FOOTPRINTS & Footprints()
Definition: board.h:307
TRACKS & Tracks()
Definition: board.h:304
DRAWINGS & Drawings()
Definition: board.h:310
A specialization of ZONE for use in footprints.
Definition: zone.h:910
void SetMaxClearance(int aClearance)
Assign a clearance resolution function object.
Definition: pns_node.h:186
void SetRuleResolver(RULE_RESOLVER *aFunc)
Definition: pns_node.h:192
void AddEdgeExclusion(std::unique_ptr< SHAPE > aShape)
Definition: pns_node.cpp:736
bool syncGraphicalItem(PNS::NODE *aWorld, PCB_SHAPE *aItem)
bool syncZone(PNS::NODE *aWorld, ZONE *aZone, SHAPE_POLY_SET *aBoardOutline)
std::unique_ptr< PNS::ARC > syncArc(PCB_ARC *aArc)
bool syncTextItem(PNS::NODE *aWorld, EDA_TEXT *aText, PCB_LAYER_ID aLayer)
std::unique_ptr< PNS::SOLID > syncPad(PAD *aPad)
std::unique_ptr< PNS::SEGMENT > syncTrack(PCB_TRACK *aTrack)
std::unique_ptr< PNS::VIA > syncVia(PCB_VIA *aVia)
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
@ CASTELLATED
a pad with a castellated through hole
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101

References PNS::NODE::Add(), PNS::NODE::AddEdgeExclusion(), CASTELLATED, PNS_PCBNEW_RULE_RESOLVER::ClearanceEpsilon(), BOARD::Drawings(), BOARD::Footprints(), BOARD_DESIGN_SETTINGS::GetBiggestClearanceValue(), BOARD::GetBoardPolygonOutlines(), BOARD::GetDesignSettings(), BOARD_ITEM::GetLayer(), PNS_KICAD_IFACE_BASE::m_board, PNS_KICAD_IFACE_BASE::m_ruleResolver, PNS_KICAD_IFACE_BASE::m_world, pad, PCB_ARC_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_SHAPE_T, PCB_TEXT_T, PCB_TEXTBOX_T, PCB_TRACE_T, PCB_VIA_T, PNS::NODE::SetMaxClearance(), PNS::NODE::SetRuleResolver(), PNS_KICAD_IFACE_BASE::syncArc(), PNS_KICAD_IFACE_BASE::syncGraphicalItem(), PNS_KICAD_IFACE_BASE::syncPad(), PNS_KICAD_IFACE_BASE::syncTextItem(), PNS_KICAD_IFACE_BASE::syncTrack(), PNS_KICAD_IFACE_BASE::syncVia(), PNS_KICAD_IFACE_BASE::syncZone(), BOARD::Tracks(), via, and BOARD::Zones().

◆ syncZone()

bool PNS_KICAD_IFACE_BASE::syncZone ( PNS::NODE aWorld,
ZONE aZone,
SHAPE_POLY_SET aBoardOutline 
)
protectedinherited

Definition at line 1218 of file pns_kicad_iface.cpp.

1219{
1220 SHAPE_POLY_SET* poly;
1221
1222 if( !aZone->GetIsRuleArea() && aZone->GetZoneName().IsEmpty() )
1223 return false;
1224
1225 // TODO handle aZone->GetDoNotAllowVias()
1226 // TODO handle rules which disallow tracks & vias
1227 if( !aZone->GetIsRuleArea() || !aZone->GetDoNotAllowTracks() )
1228 return false;
1229
1230 LSET layers = aZone->GetLayerSet();
1231
1232 poly = aZone->Outline();
1233 poly->CacheTriangulation( false );
1234
1235 if( !poly->IsTriangulationUpToDate() )
1236 {
1237 UNITS_PROVIDER unitsProvider( pcbIUScale, GetUnits() );
1238 KIDIALOG dlg( nullptr, wxString::Format( _( "%s is malformed." ),
1239 aZone->GetItemDescription( &unitsProvider ) ),
1241 dlg.ShowDetailedText( wxString::Format( _( "This zone cannot be handled by the router.\n"
1242 "Please verify it is not a self-intersecting "
1243 "polygon." ) ) );
1244 dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
1245 dlg.ShowModal();
1246
1247 return false;
1248 }
1249
1250 for( int layer = F_Cu; layer <= B_Cu; layer++ )
1251 {
1252 if( !layers[ layer ] )
1253 continue;
1254
1255 for( int outline = 0; outline < poly->OutlineCount(); outline++ )
1256 {
1257 const SHAPE_POLY_SET::TRIANGULATED_POLYGON* tri = poly->TriangulatedPolygon( outline );
1258
1259 for( size_t i = 0; i < tri->GetTriangleCount(); i++)
1260 {
1261 VECTOR2I a, b, c;
1262 tri->GetTriangle( i, a, b, c );
1263 SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
1264
1265 triShape->Append( a );
1266 triShape->Append( b );
1267 triShape->Append( c );
1268
1269 std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
1270
1271 solid->SetLayer( layer );
1272 solid->SetNet( -1 );
1273 solid->SetParent( aZone );
1274 solid->SetShape( triShape );
1275 solid->SetIsCompoundShapePrimitive();
1276 solid->SetRoutable( false );
1277
1278 aWorld->Add( std::move( solid ) );
1279 }
1280 }
1281 }
1282
1283 return true;
1284}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:46
@ KD_WARNING
Definition: confirm.h:49
virtual EDA_UNITS GetUnits() const
void GetTriangle(int index, VECTOR2I &a, VECTOR2I &b, VECTOR2I &c) const
bool IsTriangulationUpToDate() const
void CacheTriangulation(bool aPartition=true, bool aSimplify=false)
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
int OutlineCount() const
Return the number of vertices in a given outline/hole.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: zone.cpp:780
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:697
bool GetDoNotAllowTracks() const
Definition: zone.h:700
SHAPE_POLY_SET * Outline()
Definition: zone.h:312
wxString GetZoneName() const
Definition: zone.h:124
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:122
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References _, PNS::NODE::Add(), SHAPE_SIMPLE::Append(), B_Cu, SHAPE_POLY_SET::CacheTriangulation(), KIDIALOG::DoNotShowCheckbox(), F_Cu, Format(), ZONE::GetDoNotAllowTracks(), ZONE::GetIsRuleArea(), ZONE::GetItemDescription(), ZONE::GetLayerSet(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::GetTriangle(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::GetTriangleCount(), PNS_KICAD_IFACE_BASE::GetUnits(), ZONE::GetZoneName(), SHAPE_POLY_SET::IsTriangulationUpToDate(), KIDIALOG::KD_WARNING, ZONE::Outline(), SHAPE_POLY_SET::OutlineCount(), pcbIUScale, KIDIALOG::ShowModal(), and SHAPE_POLY_SET::TriangulatedPolygon().

Referenced by PNS_KICAD_IFACE_BASE::SyncWorld().

◆ UpdateItem()

void PNS_KICAD_IFACE::UpdateItem ( PNS::ITEM aItem)
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1734 of file pns_kicad_iface.cpp.

1735{
1736 BOARD_ITEM* board_item = aItem->Parent();
1737
1738 m_commit->Modify( board_item );
1739
1740 switch( aItem->Kind() )
1741 {
1742 case PNS::ITEM::ARC_T:
1743 {
1744 PNS::ARC* arc = static_cast<PNS::ARC*>( aItem );
1745 PCB_ARC* arc_board = static_cast<PCB_ARC*>( board_item );
1746 const SHAPE_ARC* arc_shape = static_cast<const SHAPE_ARC*>( arc->Shape() );
1747 arc_board->SetStart( wxPoint( arc_shape->GetP0() ) );
1748 arc_board->SetEnd( wxPoint( arc_shape->GetP1() ) );
1749 arc_board->SetMid( wxPoint( arc_shape->GetArcMid() ) );
1750 arc_board->SetWidth( arc->Width() );
1751 break;
1752 }
1753
1755 {
1756 PNS::SEGMENT* seg = static_cast<PNS::SEGMENT*>( aItem );
1757 PCB_TRACK* track = static_cast<PCB_TRACK*>( board_item );
1758 const SEG& s = seg->Seg();
1759 track->SetStart( wxPoint( s.A.x, s.A.y ) );
1760 track->SetEnd( wxPoint( s.B.x, s.B.y ) );
1761 track->SetWidth( seg->Width() );
1762 break;
1763 }
1764
1765 case PNS::ITEM::VIA_T:
1766 {
1767 PCB_VIA* via_board = static_cast<PCB_VIA*>( board_item );
1768 PNS::VIA* via = static_cast<PNS::VIA*>( aItem );
1769 via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
1770 via_board->SetWidth( via->Diameter() );
1771 via_board->SetDrill( via->Drill() );
1772 via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
1773 via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
1774 via_board->SetIsFree( via->IsFree() );
1775 via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
1776 ToLAYER_ID( via->Layers().End() ) );
1777 break;
1778 }
1779
1780 case PNS::ITEM::SOLID_T:
1781 {
1782 PAD* pad = static_cast<PAD*>( aItem->Parent() );
1783 VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1784
1785 m_fpOffsets[ pad ].p_old = pad->GetPosition();
1786 m_fpOffsets[ pad ].p_new = pos;
1787 break;
1788 }
1789
1790 default:
1791 break;
1792 }
1793}
void SetMid(const VECTOR2I &aMid)
Definition: pcb_track.h:311
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:114
const VECTOR2I & GetP1() const
Definition: shape_arc.h:113
const VECTOR2I & GetP0() const
Definition: shape_arc.h:112

References SEG::A, PNS::ITEM::ARC_T, SEG::B, SHAPE_ARC::GetArcMid(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), PNS::ITEM::Kind(), m_commit, m_fpOffsets, pad, PNS::ITEM::Parent(), PNS::SEGMENT::Seg(), PNS::ITEM::SEGMENT_T, PCB_VIA::SetDrill(), PCB_TRACK::SetEnd(), PCB_VIA::SetIsFree(), PCB_VIA::SetLayerPair(), PCB_ARC::SetMid(), BOARD_CONNECTED_ITEM::SetNetCode(), PCB_VIA::SetPosition(), PCB_TRACK::SetStart(), PCB_VIA::SetViaType(), PCB_TRACK::SetWidth(), PNS::ARC::Shape(), PNS::ITEM::SOLID_T, ToLAYER_ID(), via, PNS::ITEM::VIA_T, PNS::ARC::Width(), PNS::SEGMENT::Width(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ UpdateNet()

void PNS_KICAD_IFACE::UpdateNet ( int  aNetCode)
overridevirtual

Reimplemented from PNS_KICAD_IFACE_BASE.

Definition at line 1936 of file pns_kicad_iface.cpp.

1937{
1938 wxLogTrace( wxT( "PNS" ), wxT( "Update-net %d" ), aNetCode );
1939}

Member Data Documentation

◆ m_board

◆ m_commit

std::unique_ptr<BOARD_COMMIT> PNS_KICAD_IFACE::m_commit
private

Definition at line 143 of file pns_kicad_iface.h.

Referenced by AddItem(), Commit(), RemoveItem(), SetHostTool(), and UpdateItem().

◆ m_commitFlags

int PNS_KICAD_IFACE::m_commitFlags
private

Definition at line 144 of file pns_kicad_iface.h.

Referenced by Commit(), PNS_KICAD_IFACE(), and SetCommitFlags().

◆ m_debugDecorator

◆ m_fpOffsets

std::map<PAD*, OFFSET> PNS_KICAD_IFACE::m_fpOffsets
private

Definition at line 137 of file pns_kicad_iface.h.

Referenced by AddItem(), Commit(), RemoveItem(), and UpdateItem().

◆ m_hiddenItems

std::unordered_set<BOARD_ITEM*> PNS_KICAD_IFACE::m_hiddenItems
private

Definition at line 140 of file pns_kicad_iface.h.

Referenced by EraseView(), HideItem(), and IsItemVisible().

◆ m_previewItems

KIGFX::VIEW_GROUP* PNS_KICAD_IFACE::m_previewItems
private

◆ m_ruleResolver

◆ m_startLayer

int PNS_KICAD_IFACE_BASE::m_startLayer
protectedinherited

◆ m_tool

PCB_TOOL_BASE* PNS_KICAD_IFACE::m_tool
private

Definition at line 142 of file pns_kicad_iface.h.

Referenced by Commit(), DisplayItem(), GetUnits(), PNS_KICAD_IFACE(), and SetHostTool().

◆ m_view

KIGFX::VIEW* PNS_KICAD_IFACE::m_view
private

◆ m_world

PNS::NODE* PNS_KICAD_IFACE_BASE::m_world
protectedinherited

The documentation for this class was generated from the following files: