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
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PNS_ITEM_H
|
|
|
|
#define __PNS_ITEM_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "trace.h"
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_layerset.h"
|
|
|
|
|
2014-01-29 14:35:25 +00:00
|
|
|
class BOARD_CONNECTED_ITEM;
|
2013-09-18 17:55:16 +00:00
|
|
|
class PNS_NODE;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
enum LineMarker {
|
|
|
|
MK_HEAD = ( 1 << 0 ),
|
|
|
|
MK_VIOLATION = ( 1 << 3 ),
|
2015-02-18 00:29:54 +00:00
|
|
|
MK_LOCKED = ( 1 << 4 ),
|
|
|
|
MK_DP_COUPLED = ( 1 << 5 )
|
2014-05-14 13:53:54 +00:00
|
|
|
};
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PNS_OBJECT
|
|
|
|
*
|
|
|
|
* Abstract base class to hold ownership information about items/nodes
|
|
|
|
* used by the router.
|
|
|
|
*/
|
|
|
|
class PNS_OBJECT
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PNS_OBJECT ():
|
|
|
|
m_owner(NULL) {};
|
|
|
|
~PNS_OBJECT() {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functon SetOwner()
|
|
|
|
*
|
|
|
|
* Sets the node that owns this item. An item can belong to a single
|
|
|
|
* PNS_OBJECT or stay unowned.
|
|
|
|
*/
|
|
|
|
void SetOwner( PNS_OBJECT* aOwner )
|
|
|
|
{
|
|
|
|
m_owner = aOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function BelongsTo()
|
|
|
|
*
|
|
|
|
* @return true if the item is owned by aObj
|
|
|
|
*/
|
|
|
|
bool BelongsTo( const PNS_OBJECT* aObj ) const
|
|
|
|
{
|
|
|
|
return m_owner == aObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Owner()
|
|
|
|
*
|
|
|
|
* Returns the owner of this item, or NULL if there's none.
|
|
|
|
*/
|
|
|
|
PNS_OBJECT* Owner() const { return m_owner; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PNS_OBJECT *m_owner;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-08-03 19:11:51 +00:00
|
|
|
class PNS_ITEM : public PNS_OBJECT
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-09-26 21:53:54 +00:00
|
|
|
static const int UnusedNet = INT_MAX;
|
|
|
|
|
|
|
|
///> Supported item types
|
|
|
|
enum PnsKind
|
|
|
|
{
|
|
|
|
SOLID = 1,
|
|
|
|
LINE = 2,
|
|
|
|
JOINT = 4,
|
|
|
|
SEGMENT = 8,
|
|
|
|
VIA = 16,
|
2015-02-18 00:29:54 +00:00
|
|
|
DIFF_PAIR = 32,
|
2013-09-26 21:53:54 +00:00
|
|
|
ANY = 0xff
|
|
|
|
};
|
|
|
|
|
|
|
|
PNS_ITEM( PnsKind aKind )
|
|
|
|
{
|
|
|
|
m_net = UnusedNet;
|
|
|
|
m_movable = true;
|
|
|
|
m_kind = aKind;
|
|
|
|
m_parent = NULL;
|
|
|
|
m_owner = NULL;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_marker = 0;
|
|
|
|
m_rank = -1;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PNS_ITEM( const PNS_ITEM& aOther )
|
|
|
|
{
|
|
|
|
m_layers = aOther.m_layers;
|
|
|
|
m_net = aOther.m_net;
|
|
|
|
m_movable = aOther.m_movable;
|
|
|
|
m_kind = aOther.m_kind;
|
|
|
|
m_parent = aOther.m_parent;
|
|
|
|
m_owner = NULL;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_marker = aOther.m_marker;
|
|
|
|
m_rank = aOther.m_rank;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~PNS_ITEM();
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Clone()
|
|
|
|
*
|
2014-11-02 16:25:04 +00:00
|
|
|
* Returns a deep copy of the item
|
2014-05-14 13:53:54 +00:00
|
|
|
*/
|
2014-05-16 11:37:31 +00:00
|
|
|
virtual PNS_ITEM* Clone() const = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/*
|
|
|
|
* Function Hull()
|
|
|
|
*
|
|
|
|
* Returns a convex polygon "hull" of a the item, that is used as the walk-around
|
|
|
|
* path.
|
|
|
|
* @param aClearance defines how far from the body of the item the hull should be,
|
|
|
|
* @param aWalkaroundThickness is the width of the line that walks around this hull.
|
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0 ) const
|
|
|
|
{
|
|
|
|
return SHAPE_LINE_CHAIN();
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Kind()
|
|
|
|
*
|
|
|
|
* Returns the type (kind) of the item
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
PnsKind Kind() const
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
return m_kind;
|
|
|
|
}
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function OfKind()
|
|
|
|
*
|
|
|
|
* Returns true if the item's type matches the mask aKindMask.
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
bool OfKind( int aKindMask ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
return ( aKindMask & m_kind ) != 0;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function KindStr()
|
|
|
|
*
|
|
|
|
* Returns the kind of the item, as string
|
|
|
|
*/
|
|
|
|
const std::string KindStr() const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function SetParent()
|
|
|
|
*
|
|
|
|
* Sets the corresponding parent object in the host application's model.
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
void SetParent( BOARD_CONNECTED_ITEM* aParent )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_parent = aParent;
|
|
|
|
}
|
2014-11-02 16:25:04 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Parent()
|
|
|
|
*
|
|
|
|
* Returns the corresponding parent object in the host application's model.
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
BOARD_CONNECTED_ITEM* Parent() const
|
|
|
|
{
|
|
|
|
return m_parent;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function SetNet()
|
|
|
|
*
|
|
|
|
* Sets the item's net to aNet
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
void SetNet( int aNet )
|
|
|
|
{
|
|
|
|
m_net = aNet;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Net()
|
|
|
|
*
|
|
|
|
* Returns the item's net.
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
int Net() const
|
|
|
|
{
|
|
|
|
return m_net;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetLayers()
|
|
|
|
*
|
|
|
|
* Sets the layers spanned by the item to aLayers.
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
void SetLayers( const PNS_LAYERSET& aLayers )
|
|
|
|
{
|
|
|
|
m_layers = aLayers;
|
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 SetLayer()
|
|
|
|
*
|
|
|
|
* Sets the layers spanned by the item to a single layer aLayer.
|
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
void SetLayer( int aLayer )
|
|
|
|
{
|
|
|
|
m_layers = PNS_LAYERSET( aLayer, aLayer );
|
|
|
|
}
|
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/**
|
2014-05-14 13:53:54 +00:00
|
|
|
* Function Layers()
|
|
|
|
*
|
|
|
|
* Returns the contiguous set of layers spanned by the item.
|
|
|
|
*/
|
2014-11-02 16:25:04 +00:00
|
|
|
const PNS_LAYERSET& Layers() const
|
|
|
|
{
|
|
|
|
return m_layers;
|
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 Layer()
|
|
|
|
*
|
|
|
|
* Returns the item's layer, for single-layered items only.
|
|
|
|
*/
|
|
|
|
virtual int Layer() const
|
2014-11-02 16:25:04 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
return Layers().Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function LayersOverlap()
|
|
|
|
*
|
|
|
|
* Returns true if the set of layers spanned by aOther overlaps our
|
|
|
|
* layers.
|
|
|
|
*/
|
2014-05-16 11:37:31 +00:00
|
|
|
bool LayersOverlap( const PNS_ITEM* aOther ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return Layers().Overlaps( aOther->Layers() );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Collide()
|
|
|
|
*
|
2014-11-02 16:25:04 +00:00
|
|
|
* Checks for a collision (clearance violation) with between us and item aOther.
|
2014-05-14 13:53:54 +00:00
|
|
|
* Collision checking takes all PCB stuff into accound (layers, nets, DRC rules).
|
|
|
|
* Optionally returns a minimum translation vector for force propagation
|
|
|
|
* algorithm.
|
|
|
|
*
|
|
|
|
* @param aOther item to check collision against
|
|
|
|
* @param aClearance desired clearance
|
|
|
|
* @param aNeedMTV when true, the minimum translation vector is calculated
|
|
|
|
* @param aMTV the minimum translation vector
|
2014-11-02 16:25:04 +00:00
|
|
|
* @return true, if a collision was found.
|
2014-05-14 13:53:54 +00:00
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
virtual bool Collide( const PNS_ITEM* aOther, int aClearance, bool aNeedMTV,
|
|
|
|
VECTOR2I& aMTV ) const;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Collide()
|
|
|
|
*
|
|
|
|
* A shortcut for PNS_ITEM::Colllide() without MTV stuff.
|
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
bool Collide( const PNS_ITEM* aOther, int aClearance ) const
|
|
|
|
{
|
|
|
|
VECTOR2I dummy;
|
|
|
|
|
|
|
|
return Collide( aOther, aClearance, false, dummy );
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Function Shape()
|
|
|
|
*
|
|
|
|
* Returns the geometrical shape of the item. Used
|
|
|
|
* for collision detection & spatial indexing.
|
|
|
|
*/
|
|
|
|
virtual const SHAPE* Shape() const
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
virtual void Mark(int aMarker)
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_marker = aMarker;
|
|
|
|
}
|
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
virtual void Unmark ()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_marker = 0;
|
|
|
|
}
|
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
virtual int Marker() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return m_marker;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
virtual void SetRank( int aRank )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_rank = aRank;
|
|
|
|
}
|
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
virtual int Rank() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return m_rank;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
virtual VECTOR2I Anchor( int n ) const
|
2014-11-02 16:25:04 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
return VECTOR2I ();
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2014-11-02 16:25:04 +00:00
|
|
|
|
|
|
|
virtual int AnchorCount() const
|
|
|
|
{
|
|
|
|
return 0;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
private:
|
2013-09-26 21:53:54 +00:00
|
|
|
bool collideSimple( const PNS_ITEM* aOther, int aClearance, bool aNeedMTV,
|
|
|
|
VECTOR2I& aMTV ) const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
protected:
|
2014-05-14 13:53:54 +00:00
|
|
|
PnsKind m_kind;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
BOARD_CONNECTED_ITEM* m_parent;
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_LAYERSET m_layers;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool m_movable;
|
|
|
|
int m_net;
|
|
|
|
int m_marker;
|
|
|
|
int m_rank;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
#endif // __PNS_ITEM_H
|