New rules engine needs non-connected items as well.

This commit is contained in:
Jeff Young 2020-10-17 13:52:18 +01:00
parent 6e54856e67
commit 23d9e2e74a
6 changed files with 75 additions and 59 deletions

View File

@ -30,7 +30,7 @@
#include "pns_layerset.h" #include "pns_layerset.h"
class BOARD_CONNECTED_ITEM; class BOARD_ITEM;
namespace PNS { namespace PNS {
@ -143,8 +143,8 @@ public:
*/ */
std::string KindStr() const; std::string KindStr() const;
void SetParent( BOARD_CONNECTED_ITEM* aParent ) { m_parent = aParent; } void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
BOARD_CONNECTED_ITEM* Parent() const { return m_parent; } BOARD_ITEM* Parent() const { return m_parent; }
void SetNet( int aNet ) { m_net = aNet; } void SetNet( int aNet ) { m_net = aNet; }
int Net() const { return m_net; } int Net() const { return m_net; }
@ -254,7 +254,7 @@ private:
protected: protected:
PnsKind m_kind; PnsKind m_kind;
BOARD_CONNECTED_ITEM* m_parent; BOARD_ITEM* m_parent;
NODE* m_owner; NODE* m_owner;
LAYER_RANGE m_layers; LAYER_RANGE m_layers;

View File

@ -540,16 +540,24 @@ int PNS_PCBNEW_RULE_RESOLVER::DpNetPolarity( int aNet )
bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( const PNS::ITEM* aItem, int& aNetP, int& aNetN ) bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( const PNS::ITEM* aItem, int& aNetP, int& aNetN )
{ {
if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() ) if( !aItem || !aItem->Parent() || !aItem->Parent()->IsConnected() )
return false; return false;
wxString netNameP = aItem->Parent()->GetNet()->GetNetname(); BOARD_CONNECTED_ITEM* cItem = static_cast<BOARD_CONNECTED_ITEM*>( aItem->Parent() );
NETINFO_ITEM* netInfo = cItem->GetNet();
if( !netInfo )
return false;
wxString netNameP = netInfo->GetNetname();
wxString netNameN, netNameCoupled, netNameBase; wxString netNameN, netNameCoupled, netNameBase;
int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase ); int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
if( r == 0 ) if( r == 0 )
{
return false; return false;
}
else if( r == 1 ) else if( r == 1 )
{ {
netNameN = netNameCoupled; netNameN = netNameCoupled;
@ -982,7 +990,7 @@ bool PNS_KICAD_IFACE_BASE::syncTextItem( PNS::NODE* aWorld, EDA_TEXT* aText, PCB
solid->SetLayer( aLayer ); solid->SetLayer( aLayer );
solid->SetNet( -1 ); solid->SetNet( -1 );
solid->SetParent( nullptr ); solid->SetParent( dynamic_cast<BOARD_ITEM*>( aText ) );
solid->SetShape( new SHAPE_SEGMENT( start, end, textWidth ) ); solid->SetShape( new SHAPE_SEGMENT( start, end, textWidth ) );
solid->SetRoutable( false ); solid->SetRoutable( false );
@ -1032,7 +1040,7 @@ bool PNS_KICAD_IFACE_BASE::syncGraphicalItem( PNS::NODE* aWorld, PCB_SHAPE* aIte
solid->SetLayer( aItem->GetLayer() ); solid->SetLayer( aItem->GetLayer() );
solid->SetNet( -1 ); solid->SetNet( -1 );
solid->SetParent( nullptr ); solid->SetParent( aItem );
solid->SetShape( shape ); solid->SetShape( shape );
solid->SetRoutable( false ); solid->SetRoutable( false );
@ -1069,9 +1077,8 @@ bool PNS_KICAD_IFACE::IsOnLayer( const PNS::ITEM* aItem, int aLayer ) const
if( aLayer < 0 ) if( aLayer < 0 )
return true; return true;
if( !aItem->Parent() ) if( aItem->Parent() )
return aItem->Layers().Overlaps( aLayer ); {
switch( aItem->Parent()->Type() ) switch( aItem->Parent()->Type() )
{ {
case PCB_VIA_T: case PCB_VIA_T:
@ -1091,6 +1098,7 @@ bool PNS_KICAD_IFACE::IsOnLayer( const PNS::ITEM* aItem, int aLayer ) const
default: default:
break; break;
} }
}
return aItem->Layers().Overlaps( aLayer ); return aItem->Layers().Overlaps( aLayer );
} }
@ -1098,12 +1106,12 @@ bool PNS_KICAD_IFACE::IsOnLayer( const PNS::ITEM* aItem, int aLayer ) const
bool PNS_KICAD_IFACE::IsItemVisible( const PNS::ITEM* aItem ) const bool PNS_KICAD_IFACE::IsItemVisible( const PNS::ITEM* aItem ) const
{ {
// by default, all items are visible (new ones created by the router have parent == NULL as they have not been // by default, all items are visible (new ones created by the router have parent == NULL
// committed yet to the BOARD) // as they have not been committed yet to the BOARD)
if( !m_view || !aItem->Parent() ) if( !m_view || !aItem->Parent() )
return true; return true;
auto item = aItem->Parent(); BOARD_ITEM* item = aItem->Parent();
bool isOnVisibleLayer = true; bool isOnVisibleLayer = true;
if( m_view->GetPainter()->GetSettings()->GetHighContrast() ) if( m_view->GetPainter()->GetSettings()->GetHighContrast() )
@ -1312,7 +1320,7 @@ void PNS_KICAD_IFACE::DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aCol
void PNS_KICAD_IFACE::HideItem( PNS::ITEM* aItem ) void PNS_KICAD_IFACE::HideItem( PNS::ITEM* aItem )
{ {
BOARD_CONNECTED_ITEM* parent = aItem->Parent(); BOARD_ITEM* parent = aItem->Parent();
if( parent ) if( parent )
{ {
@ -1333,12 +1341,12 @@ void PNS_KICAD_IFACE_BASE::RemoveItem( PNS::ITEM* aItem )
void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem ) void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem )
{ {
BOARD_CONNECTED_ITEM* parent = aItem->Parent(); BOARD_ITEM* parent = aItem->Parent();
if ( aItem->OfKind(PNS::ITEM::SOLID_T) ) if ( aItem->OfKind(PNS::ITEM::SOLID_T) )
{ {
auto pad = static_cast<D_PAD*>( parent ); D_PAD* pad = static_cast<D_PAD*>( parent );
auto pos = static_cast<PNS::SOLID*>( aItem )->Pos(); VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
m_moduleOffsets[ pad ].p_old = pos; m_moduleOffsets[ pad ].p_old = pos;
return; return;
@ -1405,8 +1413,8 @@ void PNS_KICAD_IFACE::AddItem( PNS::ITEM* aItem )
case PNS::ITEM::SOLID_T: case PNS::ITEM::SOLID_T:
{ {
auto pad = static_cast<D_PAD*>( aItem->Parent() ); D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
auto pos = static_cast<PNS::SOLID*>( aItem )->Pos(); VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
m_moduleOffsets[ pad ].p_new = pos; m_moduleOffsets[ pad ].p_new = pos;
return; return;

View File

@ -126,14 +126,15 @@ public:
void UpdateNet( int aNetCode ) override; void UpdateNet( int aNetCode ) override;
private: private:
struct OFFSET { struct OFFSET
{
VECTOR2I p_old, p_new; VECTOR2I p_old, p_new;
}; };
std::map<D_PAD*, OFFSET> m_moduleOffsets; std::map<D_PAD*, OFFSET> m_moduleOffsets;
KIGFX::VIEW* m_view; KIGFX::VIEW* m_view;
KIGFX::VIEW_GROUP* m_previewItems; KIGFX::VIEW_GROUP* m_previewItems;
std::unordered_set<BOARD_CONNECTED_ITEM*> m_hiddenItems; std::unordered_set<BOARD_ITEM*> m_hiddenItems;
PCB_TOOL_BASE* m_tool; PCB_TOOL_BASE* m_tool;
std::unique_ptr<BOARD_COMMIT> m_commit; std::unique_ptr<BOARD_COMMIT> m_commit;

View File

@ -1445,16 +1445,23 @@ int NODE::QueryJoints( const BOX2I& aBox,
} }
ITEM *NODE::FindItemByParent( const BOARD_CONNECTED_ITEM* aParent ) ITEM *NODE::FindItemByParent( const BOARD_ITEM* aParent )
{ {
INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( aParent->GetNetCode() ); if( aParent->IsConnected() )
{
const BOARD_CONNECTED_ITEM* cItem = static_cast<const BOARD_CONNECTED_ITEM*>( aParent );
INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( cItem->GetNetCode() );
if( l_cur ) if( l_cur )
{ {
for( ITEM* item : *l_cur ) for( ITEM* item : *l_cur )
{
if( item->Parent() == aParent ) if( item->Parent() == aParent )
return item; return item;
} }
}
}
return NULL; return NULL;
} }

View File

@ -441,7 +441,7 @@ public:
void RemoveByMarker( int aMarker ); void RemoveByMarker( int aMarker );
ITEM* FindItemByParent( const BOARD_CONNECTED_ITEM* aParent ); ITEM* FindItemByParent( const BOARD_ITEM* aParent );
bool HasChildren() const bool HasChildren() const
{ {

View File

@ -1440,7 +1440,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
} }
else else
{ {
startItem = m_router->GetWorld()->FindItemByParent( static_cast<const BOARD_CONNECTED_ITEM*>( item ) ); startItem = m_router->GetWorld()->FindItemByParent( item );
if( startItem) if( startItem)
itemsToDrag.Add( startItem ); itemsToDrag.Add( startItem );