Skip to content

Commit

Permalink
[pns] Remove KiCad dependency from INDEX, NODE and ITEM, by using voi…
Browse files Browse the repository at this point in the history
…d* as parent and convenient template based setter/getter
  • Loading branch information
chgans committed Mar 7, 2016
1 parent a8ed2ac commit fe80433
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 38 deletions.
47 changes: 47 additions & 0 deletions pcbnew/router/TODO.txt~
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Still to be done:
- Remove KiCad dependency from node/index/item (board_connected_item)
- build libpns manually and make sure there's no other deps than math/geom and boost

Future:
- unit/regression test suites!!! (no more fear of refactoring)
- get rid of wxDeps (string, translation and timers)
- Make ALGO straight forward to use: setWorld(), execute(), getResult()
- Properly fix coupling of KiCad/PNS via and layer(set)
Can we fix the Via problem and the layer problem with one single class like PNS_LAYER_RESOLVER and/or PNS_VIA_RESOLVER
- Remove PLACER dependency from items (why pns_meander needs pns_meander_placer_base.h?)
- Remove special cases for PNS_LINE in PNS_ITEM and PNS_ITEMSET ?
- Only router and algorithm should have access to NODE
- Remove NODE dependency from items (line, meander, via), settings
- Introduce an PNS_INDEX_PROXY (same iface as index), implemented by PNS_NODE
- Remove NODE dependency from optimiser and topology (using the PNS_INDEX_PROXY trick?)

Far future:
- Make Node recursive (can branch/merge from/to anywhere, not just root)
- Create a simple ALGO_RUNNER, that can recursively be used by other algo)
- Add storage backend to NODE (typ. git)
- Add long-running router algorithm, autorouter scripts
- Get more algorithm implementation from the research community!

Node:
PNS_NODE *branch() const;
void commit (const PNS_NODE *other);
add/remove/replace
parent()
children()
root()
depth()
clear() // aka killChildren
itemsAddedToRoot()
itemsRemovedFromRoot()

Collision and hit tests
check/query colliding
find nearest obstacles

Joint utilities
jountCount()
assembleLine
findJoint
lockJoint
findLinesBetween joints
findLineEnds
8 changes: 3 additions & 5 deletions pcbnew/router/pns_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <boost/foreach.hpp>
#include <boost/range/adaptor/map.hpp>

#include <list>
#include <geometry/shape_index.h>

#include "pns_item.h"
Expand All @@ -41,7 +40,6 @@
class PNS_INDEX
{
public:
typedef std::list<PNS_ITEM*> NET_ITEMS_LIST;
typedef SHAPE_INDEX<PNS_ITEM*> ITEM_SHAPE_INDEX;
typedef boost::unordered_set<PNS_ITEM*> ITEM_SET;

Expand Down Expand Up @@ -113,7 +111,7 @@ class PNS_INDEX
*
* Returns list of all items in a given net.
*/
NET_ITEMS_LIST* GetItemsForNet( int aNet );
PNS_ITEM_LIST *GetItemsForNet( int aNet );

/**
* Function Contains()
Expand Down Expand Up @@ -150,7 +148,7 @@ class PNS_INDEX
ITEM_SHAPE_INDEX* getSubindex( const PNS_ITEM* aItem );

ITEM_SHAPE_INDEX* m_subIndices[MaxSubIndices];
std::map<int, NET_ITEMS_LIST> m_netMap;
std::map<int, PNS_ITEM_LIST> m_netMap;
ITEM_SET m_allItems;
};

Expand Down Expand Up @@ -303,7 +301,7 @@ PNS_INDEX::~PNS_INDEX()
Clear();
}

PNS_INDEX::NET_ITEMS_LIST* PNS_INDEX::GetItemsForNet( int aNet )
PNS_ITEM_LIST *PNS_INDEX::GetItemsForNet( int aNet )
{
if( m_netMap.find( aNet ) == m_netMap.end() )
return NULL;
Expand Down
21 changes: 12 additions & 9 deletions pcbnew/router/pns_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef __PNS_ITEM_H
#define __PNS_ITEM_H

#include <list>

#include <math/vector2d.h>

#include <geometry/shape.h>
Expand All @@ -30,7 +32,6 @@

#include "pns_layerset.h"

class BOARD_CONNECTED_ITEM;
class PNS_NODE;

enum LineMarker {
Expand Down Expand Up @@ -69,14 +70,14 @@ Casted pns_item_cast( From aObject )
return NULL;
}

class PNS_ITEM;
typedef std::list<PNS_ITEM*> PNS_ITEM_LIST;

/**
* Class PNS_ITEM
*
* Base class for PNS router board items. Implements the shared properties of all PCB items -
* net, spanned layers, geometric shape & refererence to owning model.
* @todo Remove dependencies on BOARD_CONNECTED_ITEM, by either:
* - Remove the whole parent story (Let the user's code track association themselves)
* - Replace BOARD_CONNECTED_ITEM *m_parent by void *m_cookie, and add convenience accessor like 'T* Parent<T>()'
*/
class PNS_ITEM
{
Expand Down Expand Up @@ -172,19 +173,21 @@ class PNS_ITEM
*
* Sets the corresponding parent object in the host application's model.
*/
void SetParent( BOARD_CONNECTED_ITEM* aParent )
template <class T>
void SetParent( T* aParent )
{
m_parent = aParent;
m_parent = static_cast<void*>(aParent);
}

/**
* Function Parent()
*
* Returns the corresponding parent object in the host application's model.
*/
BOARD_CONNECTED_ITEM* Parent() const
template <class T>
T* Parent() const
{
return m_parent;
return static_cast<T*>(m_parent);
}

/**
Expand Down Expand Up @@ -368,7 +371,7 @@ class PNS_ITEM
protected:
PnsKind m_kind;

BOARD_CONNECTED_ITEM* m_parent;
void* m_parent;
PNS_NODE* m_owner;
PNS_LAYERSET m_layers;

Expand Down
19 changes: 5 additions & 14 deletions pcbnew/router/pns_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <vector>
#include <cassert>

#include "class_board_connected_item.h"

#include <math/vector2d.h>

#include <geometry/seg.h>
Expand Down Expand Up @@ -1220,7 +1218,7 @@ void PNS_NODE::KillChildren()

void PNS_NODE::AllItemsInNet( int aNet, std::set<PNS_ITEM*>& aItems )
{
PNS_INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( aNet );
PNS_ITEM_LIST* l_cur = m_index->GetItemsForNet( aNet );

if( l_cur )
{
Expand All @@ -1230,10 +1228,10 @@ void PNS_NODE::AllItemsInNet( int aNet, std::set<PNS_ITEM*>& aItems )

if( !isRoot() )
{
PNS_INDEX::NET_ITEMS_LIST* l_root = m_root->m_index->GetItemsForNet( aNet );
PNS_ITEM_LIST* l_root = m_root->m_index->GetItemsForNet( aNet );

if( l_root )
for( PNS_INDEX::NET_ITEMS_LIST::iterator i = l_root->begin(); i!= l_root->end(); ++i )
for( PNS_ITEM_LIST::iterator i = l_root->begin(); i!= l_root->end(); ++i )
if( !overrides( *i ) )
aItems.insert( *i );
}
Expand Down Expand Up @@ -1317,14 +1315,7 @@ void PNS_NODE::SetCollisionFilter( PNS_COLLISION_FILTER* aFilter )
m_collisionFilter = aFilter;
}


PNS_ITEM *PNS_NODE::FindItemByParent( const BOARD_CONNECTED_ITEM* aParent )
PNS_ITEM_LIST *PNS_NODE::GetItemsForNet(int aNet)
{
PNS_INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( aParent->GetNetCode() );

BOOST_FOREACH( PNS_ITEM*item, *l_cur )
if( item->Parent() == aParent )
return item;

return NULL;
return m_index->GetItemsForNet( aNet );
}
8 changes: 6 additions & 2 deletions pcbnew/router/pns_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class PNS_SOLID;
class PNS_VIA;
class PNS_RATSNEST;
class PNS_INDEX;
class BOARD_CONNECTED_ITEM;

/**
* Class PNS_CLEARANCE_RESOLVER
Expand Down Expand Up @@ -394,7 +393,12 @@ class PNS_NODE
int RemoveByMarker( int aMarker );
void SetCollisionFilter( PNS_COLLISION_FILTER* aFilter );

PNS_ITEM* FindItemByParent( const BOARD_CONNECTED_ITEM *aParent );
/**
* Function GetItemsForNet()
*
* Returns list of all items in a given net.
*/
PNS_ITEM_LIST* GetItemsForNet( int aNet );

bool HasChildren() const
{
Expand Down
9 changes: 5 additions & 4 deletions pcbnew/router/pns_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ PNS_PCBNEW_CLEARANCE_RESOLVER::~PNS_PCBNEW_CLEARANCE_RESOLVER()

int PNS_PCBNEW_CLEARANCE_RESOLVER::localPadClearance( const PNS_ITEM* aItem ) const
{
if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
BOARD_CONNECTED_ITEM *parent = aItem->Parent<BOARD_CONNECTED_ITEM>();
if( !parent || parent->Type() != PCB_PAD_T )
return 0;

const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
const D_PAD* pad = static_cast<D_PAD*>( parent );
return pad->GetLocalClearance();
}

Expand Down Expand Up @@ -1020,7 +1021,7 @@ void PNS_ROUTER::updateView( PNS_NODE* aNode, PNS_ITEMSET& aCurrent )

BOOST_FOREACH( PNS_ITEM* item, removed )
{
BOARD_CONNECTED_ITEM* parent = item->Parent();
BOARD_CONNECTED_ITEM* parent = item->Parent<BOARD_CONNECTED_ITEM>();

if( parent )
{
Expand Down Expand Up @@ -1094,7 +1095,7 @@ void PNS_ROUTER::CommitRouting( PNS_NODE* aNode )

for( unsigned int i = 0; i < removed.size(); i++ )
{
BOARD_CONNECTED_ITEM* parent = removed[i]->Parent();
BOARD_CONNECTED_ITEM* parent = removed[i]->Parent<BOARD_CONNECTED_ITEM>();

if( parent )
{
Expand Down
1 change: 1 addition & 0 deletions pcbnew/router/pns_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

class BOARD;
class BOARD_ITEM;
class BOARD_CONNECTED_ITEM;
class D_PAD;
class TRACK;
class VIA;
Expand Down
19 changes: 15 additions & 4 deletions pcbnew/router/router_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ bool ROUTER_TOOL::prepareInteractive()
// for some reason I don't understand, GetNetclass() may return null sometimes...
if( m_startItem &&
m_startItem->Net() >= 0 &&
m_startItem->Parent() &&
m_startItem->Parent()->GetNetClass() )
m_startItem->Parent<BOARD_CONNECTED_ITEM>() &&
m_startItem->Parent<BOARD_CONNECTED_ITEM>()->GetNetClass() )
{
highlightNet( true, m_startItem->Net() );
// Update track width and via size shown in main toolbar comboboxes
m_frame->SetCurrentNetClass( m_startItem->Parent()->GetNetClass()->GetName() );
m_frame->SetCurrentNetClass( m_startItem->Parent<BOARD_CONNECTED_ITEM>()->GetNetClass()->GetName() );
}
else
m_frame->SetCurrentNetClass( NETCLASS::Default );
Expand Down Expand Up @@ -850,7 +850,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
m_router->SyncWorld();
m_router->SetView( getView() );

m_startItem = m_router->GetWorld()->FindItemByParent( item );
m_startItem = FindItemByParent( m_router->GetWorld(), item );

VECTOR2I p0 = ctls->GetCursorPosition();

Expand Down Expand Up @@ -908,3 +908,14 @@ void ROUTER_TOOL::importCurrentSizeSettings( PNS_SIZES_SETTINGS &aPNSSettings, c
aPNSSettings.SetViaDiameter( aBoardSettings.GetCurrentViaSize() );
aPNSSettings.SetViaDrill( aBoardSettings.GetCurrentViaDrill() );
}

PNS_ITEM *ROUTER_TOOL::FindItemByParent(PNS_NODE *aNode, const BOARD_CONNECTED_ITEM *aParent)
{
PNS_ITEM_LIST* l_cur = aNode->GetItemsForNet( aParent->GetNetCode() );

BOOST_FOREACH( PNS_ITEM*item, *l_cur )
if( item->Parent<BOARD_CONNECTED_ITEM>() == aParent )
return item;

return NULL;
}
2 changes: 2 additions & 0 deletions pcbnew/router/router_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class APIEXPORT ROUTER_TOOL : public PNS_TOOL_BASE

void initSizeSettings(PNS_SIZES_SETTINGS &aPNSSettings, const BOARD* aBoard, const PNS_ITEM* aStartItem, int aNet = -1 );
void importCurrentSizeSettings( PNS_SIZES_SETTINGS &aPNSSettings, const BOARD_DESIGN_SETTINGS &aBoardSettings );

PNS_ITEM *FindItemByParent( PNS_NODE* aNode, const BOARD_CONNECTED_ITEM* aParent );
};

#endif

0 comments on commit fe80433

Please sign in to comment.