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_LINE_H
|
|
|
|
#define __PNS_LINE_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
|
|
|
|
#include "direction.h"
|
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
|
|
|
|
class PNS_NODE;
|
|
|
|
class PNS_SEGMENT;
|
|
|
|
class PNS_VIA;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PNS_LINE
|
|
|
|
*
|
2013-10-14 11:43:57 +00:00
|
|
|
* Represents a track on a PCB, connecting two non-trivial joints (that is,
|
|
|
|
* vias, pads, junctions between multiple traces or two traces different widths
|
|
|
|
* and combinations of these). PNS_LINEs are NOT stored in the model (PNS_NODE).
|
|
|
|
* Instead, they are assembled on-the-fly, based on a via/pad/segment that
|
2014-05-14 13:53:54 +00:00
|
|
|
* belongs to/starts/ends them.
|
2013-09-18 17:55:16 +00:00
|
|
|
*
|
2013-10-14 11:43:57 +00:00
|
|
|
* PNS_LINEs can be either loose (consisting of segments that do not belong to
|
|
|
|
* any PNS_NODE) or owned (with segments taken from a PNS_NODE) - these are
|
2013-09-26 21:53:54 +00:00
|
|
|
* returned by PNS_NODE::AssembleLine and friends.
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* A PNS_LINE may have a PNS_VIA attached at its end (i.e. the last point) - this is used by via
|
2013-09-26 21:53:54 +00:00
|
|
|
* dragging/force propagation stuff.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#define PNS_HULL_MARGIN 10
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
class PNS_LINE : public PNS_ITEM
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-05-16 11:37:31 +00:00
|
|
|
typedef std::vector<PNS_SEGMENT*> SEGMENT_REFS;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* Makes an empty line.
|
|
|
|
*/
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_LINE() : PNS_ITEM( LINE )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
m_segmentRefs = NULL;
|
|
|
|
m_hasVia = false;
|
2015-04-12 17:44:46 +00:00
|
|
|
m_width = 1; // Dummy value
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 21:42:05 +00:00
|
|
|
PNS_LINE( const PNS_LINE& aOther );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copies properties (net, layers, etc.) from a base line and replaces the shape
|
|
|
|
* by another
|
2013-09-26 21:53:54 +00:00
|
|
|
**/
|
|
|
|
PNS_LINE( const PNS_LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
|
|
|
|
PNS_ITEM( aBase ),
|
|
|
|
m_line( aLine ),
|
|
|
|
m_width( aBase.m_width )
|
|
|
|
{
|
|
|
|
m_net = aBase.m_net;
|
|
|
|
m_layers = aBase.m_layers;
|
|
|
|
m_segmentRefs = NULL;
|
|
|
|
m_hasVia = false;
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
~PNS_LINE();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
static inline bool ClassOf( const PNS_ITEM* aItem )
|
|
|
|
{
|
|
|
|
return aItem && LINE == aItem->Kind();
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/// @copydoc PNS_ITEM::Clone()
|
2014-05-16 11:37:31 +00:00
|
|
|
virtual PNS_LINE* Clone() const;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const PNS_LINE& operator=( const PNS_LINE& aOther );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
///> Assigns a shape to the line (a polyline/line chain)
|
2014-05-16 11:37:31 +00:00
|
|
|
void SetShape( const SHAPE_LINE_CHAIN& aLine )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_line = aLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
///> Returns the shape of the line
|
2015-02-18 16:53:46 +00:00
|
|
|
const SHAPE* Shape() const
|
|
|
|
{
|
|
|
|
return &m_line;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///> Modifiable accessor to the underlying shape
|
2015-02-18 16:53:46 +00:00
|
|
|
SHAPE_LINE_CHAIN& Line()
|
|
|
|
{
|
|
|
|
return m_line;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///> Const accessor to the underlying shape
|
2015-02-18 16:53:46 +00:00
|
|
|
const SHAPE_LINE_CHAIN& CLine() const
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
return m_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
///> Returns the number of segments in the line
|
2015-02-18 16:53:46 +00:00
|
|
|
int SegmentCount() const
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return m_line.SegmentCount();
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns the number of points in the line
|
2015-02-18 16:53:46 +00:00
|
|
|
int PointCount() const
|
|
|
|
{
|
|
|
|
return m_line.PointCount();
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns the aIdx-th point of the line
|
2015-02-18 16:53:46 +00:00
|
|
|
const VECTOR2I& CPoint( int aIdx ) const
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
return m_line.CPoint( aIdx );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns the aIdx-th segment of the line
|
2014-05-16 11:37:31 +00:00
|
|
|
const SEG CSegment( int aIdx ) const
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
return m_line.CSegment( aIdx );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Sets line width
|
2015-02-18 16:53:46 +00:00
|
|
|
void SetWidth( int aWidth )
|
|
|
|
{
|
|
|
|
m_width = aWidth;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns line width
|
2015-02-18 16:53:46 +00:00
|
|
|
int Width() const
|
|
|
|
{
|
|
|
|
return m_width;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///> Returns true if the line is geometrically identical as line aOther
|
|
|
|
bool CompareGeometry( const PNS_LINE& aOther );
|
|
|
|
|
|
|
|
///> Reverses the point/vertex order
|
|
|
|
void Reverse();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/* Linking functions */
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
///> Adds a reference to a segment registered in a PNS_NODE that is a part of this line.
|
2013-09-26 21:53:54 +00:00
|
|
|
void LinkSegment( PNS_SEGMENT* aSeg )
|
|
|
|
{
|
|
|
|
if( !m_segmentRefs )
|
2014-05-16 11:37:31 +00:00
|
|
|
m_segmentRefs = new SEGMENT_REFS();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
m_segmentRefs->push_back( aSeg );
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns the list of segments from the owning node that constitute this
|
|
|
|
///> line (or NULL if the line is not linked)
|
2014-05-16 11:37:31 +00:00
|
|
|
SEGMENT_REFS* LinkedSegments()
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
return m_segmentRefs;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool IsLinked() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_segmentRefs != NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Checks if the segment aSeg is a part of the line.
|
2013-09-26 21:53:54 +00:00
|
|
|
bool ContainsSegment( PNS_SEGMENT* aSeg ) const
|
|
|
|
{
|
|
|
|
if( !m_segmentRefs )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return std::find( m_segmentRefs->begin(), m_segmentRefs->end(),
|
|
|
|
aSeg ) != m_segmentRefs->end();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_SEGMENT* GetLink( int aIndex ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return (*m_segmentRefs) [ aIndex ];
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Erases the linking information. Used to detach the line from the owning node.
|
|
|
|
void ClearSegmentLinks();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns the number of segments that were assembled together to form this line.
|
2014-05-16 11:37:31 +00:00
|
|
|
int LinkCount() const
|
|
|
|
{
|
|
|
|
if( !m_segmentRefs )
|
2014-05-14 13:53:54 +00:00
|
|
|
return -1;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return m_segmentRefs->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
///> Clips the line to the nearest obstacle, traversing from the line's start vertex (0).
|
|
|
|
///> Returns the clipped line.
|
2013-09-26 21:53:54 +00:00
|
|
|
const PNS_LINE ClipToNearestObstacle( PNS_NODE* aNode ) const;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
///> Clips the line to a given range of vertices.
|
2014-05-14 13:53:54 +00:00
|
|
|
void ClipVertexRange ( int aStart, int aEnd );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
///> Returns the number of corners of angles specified by mask aAngles.
|
|
|
|
int CountCorners( int aAngles );
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
///> Calculates a line thightly wrapping a convex hull
|
2013-09-26 21:53:54 +00:00
|
|
|
///> of an obstacle object (aObstacle).
|
|
|
|
///> aPrePath = path from origin to the obstacle
|
|
|
|
///> aWalkaroundPath = path around the obstacle
|
|
|
|
///> aPostPath = past from obstacle till the end
|
2014-05-14 13:53:54 +00:00
|
|
|
///> aCW = whether to walk around in clockwise or counter-clockwise direction.
|
2014-05-16 11:37:31 +00:00
|
|
|
bool Walkaround( SHAPE_LINE_CHAIN aObstacle,
|
|
|
|
SHAPE_LINE_CHAIN& aPre,
|
|
|
|
SHAPE_LINE_CHAIN& aWalk,
|
|
|
|
SHAPE_LINE_CHAIN& aPost,
|
|
|
|
bool aCw ) const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
void Walkaround( const SHAPE_LINE_CHAIN& aObstacle,
|
|
|
|
SHAPE_LINE_CHAIN& aPath,
|
|
|
|
bool aCw ) const;
|
|
|
|
|
|
|
|
bool Is45Degree();
|
|
|
|
|
|
|
|
///> Prints out all linked segments
|
|
|
|
void ShowLinks();
|
|
|
|
|
|
|
|
bool EndsWithVia() const { return m_hasVia; }
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void AppendVia( const PNS_VIA& aVia );
|
2013-09-26 21:53:54 +00:00
|
|
|
void RemoveVia() { m_hasVia = false; }
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const PNS_VIA& Via() const { return m_via; }
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
virtual void Mark( int aMarker );
|
2014-05-14 13:53:54 +00:00
|
|
|
virtual void Unmark ();
|
|
|
|
virtual int Marker() const;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void DragSegment( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0 );
|
|
|
|
void DragCorner( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void SetRank( int aRank );
|
2014-05-14 13:53:54 +00:00
|
|
|
int Rank() const;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool HasLoops() const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
OPT_BOX2I ChangedArea( const PNS_LINE* aOther ) const;
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
private:
|
2014-05-16 11:37:31 +00:00
|
|
|
VECTOR2I snapToNeighbourSegments( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I &aP,
|
|
|
|
int aIndex, int aThreshold) const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I &aP,
|
|
|
|
int aIndex, int aThreshold ) const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Copies m_segmentRefs from the line aParent.
|
2014-05-16 11:37:31 +00:00
|
|
|
void copyLinks( const PNS_LINE* aParent ) ;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> List of segments in the owning PNS_NODE (PNS_ITEM::m_owner) that constitute this line, or NULL
|
|
|
|
///> if the line is not a part of any node.
|
2014-05-16 11:37:31 +00:00
|
|
|
SEGMENT_REFS* m_segmentRefs;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
///> The actual shape of the line
|
2013-09-26 21:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN m_line;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> our width
|
2013-09-26 21:53:54 +00:00
|
|
|
int m_width;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> If true, the line ends with a via
|
2013-09-26 21:53:54 +00:00
|
|
|
bool m_hasVia;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Via at the end point, if m_hasVia == true
|
|
|
|
PNS_VIA m_via;
|
2013-09-26 21:53:54 +00:00
|
|
|
};
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
#endif // __PNS_LINE_H
|