2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-18 17:55:16 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#ifndef __PNS_NODE_H
|
|
|
|
#define __PNS_NODE_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
#include <unordered_map>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <core/optional.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_index.h>
|
|
|
|
|
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_joint.h"
|
|
|
|
#include "pns_itemset.h"
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class SEGMENT;
|
|
|
|
class LINE;
|
|
|
|
class SOLID;
|
|
|
|
class VIA;
|
|
|
|
class INDEX;
|
|
|
|
class ROUTER;
|
|
|
|
class NODE;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
2016-08-29 17:31:13 +00:00
|
|
|
* Class RULE_RESOLVER
|
2014-05-14 13:53:54 +00:00
|
|
|
*
|
2016-08-15 15:16:47 +00:00
|
|
|
* An abstract function object, returning a design rule (clearance, diff pair gap, etc) required between two items.
|
2014-05-14 13:53:54 +00:00
|
|
|
**/
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class RULE_RESOLVER
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-08-29 17:31:13 +00:00
|
|
|
virtual ~RULE_RESOLVER() {}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
virtual int Clearance( const ITEM* aA, const ITEM* aB ) const = 0;
|
|
|
|
virtual int Clearance( int aNetCode ) const = 0;
|
2016-08-15 15:16:53 +00:00
|
|
|
virtual void OverrideClearance( bool aEnable, int aNetA = 0, int aNetB = 0, int aClearance = 0 ) = 0;
|
2016-08-15 15:16:47 +00:00
|
|
|
virtual void UseDpGap( bool aUseDpGap ) = 0;
|
|
|
|
virtual int DpCoupledNet( int aNet ) = 0;
|
|
|
|
virtual int DpNetPolarity( int aNet ) = 0;
|
2016-08-29 17:31:13 +00:00
|
|
|
virtual bool DpNetPair( ITEM* aItem, int& aNetP, int& aNetN ) = 0;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-08-29 17:31:13 +00:00
|
|
|
* Struct OBSTACLE
|
2013-09-18 17:55:16 +00:00
|
|
|
*
|
|
|
|
* Holds an object colliding with another object, along with
|
|
|
|
* some useful data about the collision.
|
|
|
|
**/
|
2016-08-29 17:31:13 +00:00
|
|
|
struct OBSTACLE
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
///> Item we search collisions with
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM* m_head;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
///> Item found to be colliding with m_head
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* m_item;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
///> Hull of the colliding m_item
|
|
|
|
SHAPE_LINE_CHAIN m_hull;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> First and last intersection point between the head item and the hull
|
2014-05-16 11:37:31 +00:00
|
|
|
///> of the colliding m_item
|
|
|
|
VECTOR2I m_ipFirst, m_ipLast;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> ... and the distance thereof
|
2014-05-16 11:37:31 +00:00
|
|
|
int m_distFirst, m_distLast;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
/**
|
2016-08-29 17:31:13 +00:00
|
|
|
* Struct OBSTACLE_VISITOR
|
2015-02-18 00:29:54 +00:00
|
|
|
**/
|
2016-08-29 17:31:13 +00:00
|
|
|
class OBSTACLE_VISITOR {
|
2016-08-15 15:16:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OBSTACLE_VISITOR( const ITEM* aItem );
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void SetWorld( const NODE* aNode, const NODE* aOverride = NULL );
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
virtual bool operator()( ITEM* aCandidate ) = 0;
|
2016-08-15 15:16:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool visit( ITEM* aCandidate );
|
2016-08-15 15:16:49 +00:00
|
|
|
|
|
|
|
///> the item we are looking for collisions with
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM* m_item;
|
2016-08-15 15:16:49 +00:00
|
|
|
|
|
|
|
///> node we are searching in (either root or a branch)
|
2016-08-29 17:31:13 +00:00
|
|
|
const NODE* m_node;
|
2016-08-15 15:16:49 +00:00
|
|
|
|
|
|
|
///> node that overrides root entries
|
2016-08-29 17:31:13 +00:00
|
|
|
const NODE* m_override;
|
2016-08-15 15:16:49 +00:00
|
|
|
|
|
|
|
///> additional clearance
|
|
|
|
int m_extraClearance;
|
2015-02-18 00:29:54 +00:00
|
|
|
};
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
/**
|
2016-08-29 17:31:13 +00:00
|
|
|
* Class NODE
|
2013-09-18 17:55:16 +00:00
|
|
|
*
|
2013-10-14 11:43:57 +00:00
|
|
|
* Keeps the router "world" - i.e. all the tracks, vias, solids in a
|
2013-09-26 21:53:54 +00:00
|
|
|
* hierarchical and indexed way.
|
2013-09-18 17:55:16 +00:00
|
|
|
* Features:
|
|
|
|
* - spatial-indexed container for PCB item shapes
|
2014-05-14 13:53:54 +00:00
|
|
|
* - collision search & clearance checking
|
2013-09-18 17:55:16 +00:00
|
|
|
* - assembly of lines connecting joints, finding loops and unique paths
|
2013-10-14 11:43:57 +00:00
|
|
|
* - lightweight cloning/branching (for recursive optimization and shove
|
2013-09-26 21:53:54 +00:00
|
|
|
* springback)
|
2013-09-18 17:55:16 +00:00
|
|
|
**/
|
2016-08-29 17:31:13 +00:00
|
|
|
class NODE
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2013-09-18 17:55:16 +00:00
|
|
|
public:
|
2017-11-01 11:14:16 +00:00
|
|
|
typedef OPT<OBSTACLE> OPT_OBSTACLE;
|
2016-08-29 17:31:13 +00:00
|
|
|
typedef std::vector<ITEM*> ITEM_VECTOR;
|
|
|
|
typedef std::vector<OBSTACLE> OBSTACLES;
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE();
|
|
|
|
~NODE();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
///> Returns the expected clearance between items a and b.
|
2016-08-29 17:31:13 +00:00
|
|
|
int GetClearance( const ITEM* aA, const ITEM* aB ) const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
///> Returns the pre-set worst case clearance between any pair of items
|
2014-05-16 11:37:31 +00:00
|
|
|
int GetMaxClearance() const
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
return m_maxClearance;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Sets the worst-case clerance between any pair of items
|
2014-05-16 11:37:31 +00:00
|
|
|
void SetMaxClearance( int aClearance )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
m_maxClearance = aClearance;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Assigns a clerance resolution function object
|
2016-08-29 17:31:13 +00:00
|
|
|
void SetRuleResolver( RULE_RESOLVER* aFunc )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
m_ruleResolver = aFunc;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
RULE_RESOLVER* GetRuleResolver()
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
return m_ruleResolver;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
///> Returns the number of joints
|
|
|
|
int JointCount() const
|
|
|
|
{
|
|
|
|
return m_joints.size();
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns the number of nodes in the inheritance chain (wrs to the root node)
|
2014-11-02 16:25:04 +00:00
|
|
|
int Depth() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return m_depth;
|
|
|
|
}
|
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function QueryColliding()
|
|
|
|
*
|
|
|
|
* Finds items collliding (closer than clearance) with the item aItem.
|
|
|
|
* @param aItem item to check collisions against
|
|
|
|
* @param aObstacles set of colliding objects found
|
|
|
|
* @param aKindMask mask of obstacle types to take into account
|
|
|
|
* @param aLimitCount stop looking for collisions after finding this number of colliding items
|
|
|
|
* @return number of obstacles found
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
int QueryColliding( const ITEM* aItem,
|
|
|
|
OBSTACLES& aObstacles,
|
|
|
|
int aKindMask = ITEM::ANY_T,
|
|
|
|
int aLimitCount = -1,
|
|
|
|
bool aDifferentNetsOnly = true,
|
|
|
|
int aForceClearance = -1 );
|
|
|
|
|
|
|
|
int QueryColliding( const ITEM* aItem,
|
|
|
|
OBSTACLE_VISITOR& aVisitor
|
2016-08-15 15:16:49 +00:00
|
|
|
);
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function NearestObstacle()
|
|
|
|
*
|
|
|
|
* Follows the line in search of an obstacle that is nearest to the starting to the line's starting
|
|
|
|
* point.
|
|
|
|
* @param aItem the item to find collisions with
|
|
|
|
* @param aKindMask mask of obstacle types to take into account
|
|
|
|
* @return the obstacle, if found, otherwise empty.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
OPT_OBSTACLE NearestObstacle( const LINE* aItem,
|
|
|
|
int aKindMask = ITEM::ANY_T,
|
|
|
|
const std::set<ITEM*>* aRestrictedSet = NULL );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function CheckColliding()
|
|
|
|
*
|
|
|
|
* Checks if the item collides with anything else in the world,
|
|
|
|
* and if found, returns the obstacle.
|
|
|
|
* @param aItem the item to find collisions with
|
|
|
|
* @param aKindMask mask of obstacle types to take into account
|
|
|
|
* @return the obstacle, if found, otherwise empty.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
OPT_OBSTACLE CheckColliding( const ITEM* aItem,
|
|
|
|
int aKindMask = ITEM::ANY_T );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
|
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function CheckColliding()
|
|
|
|
*
|
|
|
|
* Checks if any item in the set collides with anything else in the world,
|
|
|
|
* and if found, returns the obstacle.
|
|
|
|
* @param aSet set of items to find collisions with
|
|
|
|
* @param aKindMask mask of obstacle types to take into account
|
|
|
|
* @return the obstacle, if found, otherwise empty.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
OPT_OBSTACLE CheckColliding( const ITEM_SET& aSet,
|
|
|
|
int aKindMask = ITEM::ANY_T );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function CheckColliding()
|
|
|
|
*
|
2014-11-02 16:25:04 +00:00
|
|
|
* Checks if 2 items collide.
|
2014-05-14 13:53:54 +00:00
|
|
|
* and if found, returns the obstacle.
|
2014-11-02 16:25:04 +00:00
|
|
|
* @param aItemA first item to find collisions with
|
|
|
|
* @param aItemB second item to find collisions with
|
2014-05-14 13:53:54 +00:00
|
|
|
* @param aKindMask mask of obstacle types to take into account
|
|
|
|
* @return the obstacle, if found, otherwise empty.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
bool CheckColliding( const ITEM* aItemA,
|
|
|
|
const ITEM* aItemB,
|
|
|
|
int aKindMask = ITEM::ANY_T,
|
|
|
|
int aForceClearance = -1 );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function HitTest()
|
|
|
|
*
|
|
|
|
* Finds all items that contain the point aPoint.
|
|
|
|
* @param aPoint the point
|
|
|
|
* @return the items
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET HitTest( const VECTOR2I& aPoint ) const;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Add()
|
|
|
|
*
|
2014-11-02 16:25:04 +00:00
|
|
|
* Adds an item to the current node.
|
2017-06-22 07:01:29 +00:00
|
|
|
* @param aSegment item to add
|
2014-11-02 16:25:04 +00:00
|
|
|
* @param aAllowRedundant if true, duplicate items are allowed (e.g. a segment or via
|
2014-05-14 13:53:54 +00:00
|
|
|
* at the same coordinates as an existing one)
|
|
|
|
*/
|
2016-08-30 15:28:35 +00:00
|
|
|
void Add( std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant = false );
|
|
|
|
void Add( std::unique_ptr< SOLID > aSolid );
|
|
|
|
void Add( std::unique_ptr< VIA > aVia );
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void Add( LINE& aLine, bool aAllowRedundant = false );
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant = false );
|
|
|
|
|
|
|
|
public:
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function Remove()
|
|
|
|
*
|
|
|
|
* Just as the name says, removes an item from this branch.
|
|
|
|
*/
|
2016-08-30 17:01:30 +00:00
|
|
|
void Remove( SOLID* aSolid );
|
|
|
|
void Remove( VIA* aVia );
|
|
|
|
void Remove( SEGMENT* aSegment );
|
2016-08-29 17:31:13 +00:00
|
|
|
void Remove( ITEM* aItem );
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
public:
|
2015-02-18 00:29:54 +00:00
|
|
|
/**
|
|
|
|
* Function Remove()
|
|
|
|
*
|
|
|
|
* Just as the name says, removes a line from this branch.
|
2017-06-22 07:01:29 +00:00
|
|
|
* @param aLine item to remove
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
void Remove( LINE& aLine );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function Replace()
|
|
|
|
*
|
|
|
|
* Just as the name says, replaces an item with another one.
|
|
|
|
* @param aOldItem item to be removed
|
|
|
|
* @param aNewItem item add instead
|
|
|
|
*/
|
2016-08-30 15:28:35 +00:00
|
|
|
void Replace( ITEM* aOldItem, std::unique_ptr< ITEM > aNewItem );
|
|
|
|
void Replace( LINE& aOldLine, LINE& aNewLine );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Branch()
|
|
|
|
*
|
|
|
|
* Creates a lightweight copy (called branch) of self that tracks
|
|
|
|
* the changes (added/removed items) wrs to the root. Note that if there are
|
|
|
|
* any branches in use, their parents must NOT be deleted.
|
|
|
|
* @return the new branch
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* Branch();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function AssembleLine()
|
|
|
|
*
|
2014-11-02 16:25:04 +00:00
|
|
|
* Follows the joint map to assemble a line connecting two non-trivial
|
2014-05-14 13:53:54 +00:00
|
|
|
* joints starting from segment aSeg.
|
|
|
|
* @param aSeg the initial segment
|
|
|
|
* @param aOriginSegmentIndex index of aSeg in the resulting line
|
|
|
|
* @return the line
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE AssembleLine( SEGMENT* aSeg, int* aOriginSegmentIndex = NULL,
|
2015-10-09 12:31:06 +00:00
|
|
|
bool aStopAtLockedJoints = false );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
///> Prints the contents and joints structure
|
2014-05-16 11:37:31 +00:00
|
|
|
void Dump( bool aLong = false );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetUpdatedItems()
|
|
|
|
*
|
|
|
|
* Returns the lists of items removed and added in this branch, with
|
|
|
|
* respect to the root branch.
|
|
|
|
* @param aRemoved removed items
|
|
|
|
* @param aAdded added items
|
|
|
|
*/
|
2014-05-16 11:37:31 +00:00
|
|
|
void GetUpdatedItems( ITEM_VECTOR& aRemoved, ITEM_VECTOR& aAdded );
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Commit()
|
|
|
|
*
|
|
|
|
* Applies the changes from a given branch (aNode) to the root branch. Called on
|
|
|
|
* a non-root branch will fail. Calling commit also kills all children nodes of the root branch.
|
|
|
|
* @param aNode node to commit changes from
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
void Commit( NODE* aNode );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function FindJoint()
|
|
|
|
*
|
|
|
|
* Searches for a joint at a given position, layer and belonging to given net.
|
|
|
|
* @return the joint, if found, otherwise empty
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT* FindJoint( const VECTOR2I& aPos, int aLayer, int aNet );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LockJoint( const VECTOR2I& aPos, const ITEM* aItem, bool aLock );
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function FindJoint()
|
|
|
|
*
|
|
|
|
* Searches for a joint at a given position, linked to given item.
|
|
|
|
* @return the joint, if found, otherwise empty
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT* FindJoint( const VECTOR2I& aPos, const ITEM* aItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return FindJoint( aPos, aItem->Layers().Start(), aItem->Net() );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
#if 0
|
2016-08-29 17:31:13 +00:00
|
|
|
void MapConnectivity( JOINT* aStart, std::vector<JOINT*> & aFoundJoints );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* NearestUnconnectedItem( JOINT* aStart, int* aAnchor = NULL,
|
|
|
|
int aKindMask = ITEM::ANY_T);
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
#endif
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> finds all lines between a pair of joints. Used by the loop removal procedure.
|
2016-08-29 17:31:13 +00:00
|
|
|
int FindLinesBetweenJoints( JOINT& aA,
|
|
|
|
JOINT& aB,
|
|
|
|
std::vector<LINE>& aLines );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
///> finds the joints corresponding to the ends of line aLine
|
2016-08-29 17:31:13 +00:00
|
|
|
void FindLineEnds( const LINE& aLine, JOINT& aA, JOINT& aB );
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
///> Destroys all child nodes. Applicable only to the root node.
|
|
|
|
void KillChildren();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void AllItemsInNet( int aNet, std::set<ITEM*>& aItems );
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void ClearRanks( int aMarkerMask = MK_HEAD | MK_VIOLATION );
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int FindByMarker( int aMarker, ITEM_SET& aItems );
|
2014-05-16 11:37:31 +00:00
|
|
|
int RemoveByMarker( int aMarker );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* FindItemByParent( const BOARD_CONNECTED_ITEM* aParent );
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2015-09-14 16:40:29 +00:00
|
|
|
bool HasChildren() const
|
|
|
|
{
|
|
|
|
return !m_children.empty();
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
///> checks if this branch contains an updated version of the m_item
|
|
|
|
///> from the root branch.
|
2016-08-29 17:31:13 +00:00
|
|
|
bool Overrides( ITEM* aItem ) const
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
|
|
|
return m_override.find( aItem ) != m_override.end();
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
private:
|
2016-08-15 15:16:49 +00:00
|
|
|
struct DEFAULT_OBSTACLE_VISITOR;
|
2017-11-01 11:14:16 +00:00
|
|
|
typedef std::unordered_multimap<JOINT::HASH_TAG, JOINT, JOINT::JOINT_TAG_HASH> JOINT_MAP;
|
2014-05-16 11:37:31 +00:00
|
|
|
typedef JOINT_MAP::value_type TagJointPair;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
/// nodes are not copyable
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE( const NODE& aB );
|
|
|
|
NODE& operator=( const NODE& aB );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> tries to find matching joint and creates a new one if not found
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT& touchJoint( const VECTOR2I& aPos,
|
|
|
|
const LAYER_RANGE& aLayers,
|
|
|
|
int aNet );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
///> touches a joint and links it to an m_item
|
2017-01-25 09:33:49 +00:00
|
|
|
void linkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> unlinks an item from a joint
|
2017-01-25 09:33:49 +00:00
|
|
|
void unlinkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> helpers for adding/removing items
|
2016-08-29 17:31:13 +00:00
|
|
|
void addSolid( SOLID* aSeg );
|
2016-08-30 15:28:35 +00:00
|
|
|
void addSegment( SEGMENT* aSeg );
|
2016-08-29 17:31:13 +00:00
|
|
|
void addVia( VIA* aVia );
|
2017-01-25 09:33:49 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void removeLine( LINE& aLine );
|
|
|
|
void removeSolidIndex( SOLID* aSeg );
|
|
|
|
void removeSegmentIndex( SEGMENT* aSeg );
|
|
|
|
void removeViaIndex( VIA* aVia );
|
2016-08-29 17:31:13 +00:00
|
|
|
|
|
|
|
void doRemove( ITEM* aItem );
|
2013-09-26 21:53:54 +00:00
|
|
|
void unlinkParent();
|
|
|
|
void releaseChildren();
|
2015-08-03 19:11:51 +00:00
|
|
|
void releaseGarbage();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
bool isRoot() const
|
|
|
|
{
|
|
|
|
return m_parent == NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-30 18:55:00 +00:00
|
|
|
SEGMENT* findRedundantSegment( const VECTOR2I& A, const VECTOR2I& B,
|
|
|
|
const LAYER_RANGE & lr, int aNet );
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT* findRedundantSegment( SEGMENT* aSeg );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> scans the joint map, forming a line starting from segment (current).
|
2016-08-29 17:31:13 +00:00
|
|
|
void followLine( SEGMENT* aCurrent,
|
|
|
|
bool aScanDirection,
|
|
|
|
int& aPos,
|
|
|
|
int aLimit,
|
|
|
|
VECTOR2I* aCorners,
|
|
|
|
SEGMENT** aSegments,
|
|
|
|
bool& aGuardHit,
|
|
|
|
bool aStopAtLockedJoints );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
///> hash table with the joints, linking the items. Joints are hashed by
|
2013-09-26 21:53:54 +00:00
|
|
|
///> their position, layer set and net.
|
2014-05-16 11:37:31 +00:00
|
|
|
JOINT_MAP m_joints;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> node this node was branched from
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_parent;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> root node of the whole hierarchy
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_root;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> list of nodes branched from this one
|
2016-08-29 17:31:13 +00:00
|
|
|
std::set<NODE*> m_children;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> hash of root's items that have been changed in this node
|
2017-11-01 11:14:16 +00:00
|
|
|
std::unordered_set<ITEM*> m_override;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> worst case item-item clearance
|
|
|
|
int m_maxClearance;
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
///> Design rules resolver
|
2016-08-29 17:31:13 +00:00
|
|
|
RULE_RESOLVER* m_ruleResolver;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> Geometric/Net index of the items
|
2016-08-29 17:31:13 +00:00
|
|
|
INDEX* m_index;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> depth of the node (number of parent nodes in the inheritance chain)
|
|
|
|
int m_depth;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2017-11-01 11:14:16 +00:00
|
|
|
std::unordered_set<ITEM*> m_garbageItems;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#endif
|