2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2017-01-17 14:06:33 +00:00
|
|
|
* Copyright (C) 2013-2017 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
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PNS_LINE_H
|
|
|
|
#define __PNS_LINE_H
|
|
|
|
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/box2.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
2017-03-22 12:35:07 +00:00
|
|
|
#include <geometry/direction45.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
|
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_via.h"
|
2020-04-15 20:16:24 +00:00
|
|
|
#include "pns_link_holder.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
class LINKED_ITEM;
|
2016-08-29 17:31:13 +00:00
|
|
|
class NODE;
|
|
|
|
class VIA;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
/**
|
2020-01-10 14:31:00 +00:00
|
|
|
* LINE
|
2013-09-18 17:55:16 +00:00
|
|
|
*
|
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
|
2016-08-29 17:31:13 +00:00
|
|
|
* and combinations of these). PNS_LINEs are NOT stored in the model (NODE).
|
2013-10-14 11:43:57 +00:00
|
|
|
* 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
|
2016-08-29 17:31:13 +00:00
|
|
|
* any NODE) or owned (with segments taken from a NODE) - these are
|
|
|
|
* returned by NODE::AssembleLine and friends.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2016-08-29 17:31:13 +00:00
|
|
|
* A LINE may have a 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
|
|
|
|
|
2020-04-15 20:16:24 +00:00
|
|
|
class LINE : public LINK_HOLDER
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* Makes an empty line.
|
|
|
|
*/
|
2020-12-30 19:05:48 +00:00
|
|
|
LINE() :
|
2021-01-01 17:17:55 +00:00
|
|
|
LINK_HOLDER( LINE_T ),
|
|
|
|
m_blockingObstacle( nullptr )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
m_hasVia = false;
|
2015-04-12 17:44:46 +00:00
|
|
|
m_width = 1; // Dummy value
|
2019-05-17 00:13:21 +00:00
|
|
|
m_snapThreshhold = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE( const 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
|
|
|
**/
|
2020-12-30 19:05:48 +00:00
|
|
|
LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
|
|
|
|
LINK_HOLDER( aBase ),
|
|
|
|
m_line( aLine ),
|
|
|
|
m_width( aBase.m_width ),
|
2021-01-01 17:17:55 +00:00
|
|
|
m_snapThreshhold( aBase.m_snapThreshhold ),
|
|
|
|
m_blockingObstacle( nullptr )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
m_net = aBase.m_net;
|
|
|
|
m_layers = aBase.m_layers;
|
|
|
|
m_hasVia = false;
|
|
|
|
}
|
|
|
|
|
2019-07-22 23:46:20 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* Constructs a LINE for a lone VIA (ie a stitching via).
|
|
|
|
* @param aVia
|
|
|
|
*/
|
|
|
|
LINE( const VIA& aVia ) :
|
2021-01-01 17:17:55 +00:00
|
|
|
LINK_HOLDER( LINE_T ),
|
|
|
|
m_blockingObstacle( nullptr )
|
2019-07-22 23:46:20 +00:00
|
|
|
{
|
|
|
|
m_hasVia = true;
|
|
|
|
m_via = aVia;
|
|
|
|
m_width = aVia.Diameter();
|
|
|
|
m_net = aVia.Net();
|
|
|
|
m_layers = aVia.Layers();
|
|
|
|
m_rank = aVia.Rank();
|
2019-05-17 00:13:21 +00:00
|
|
|
m_snapThreshhold = 0;
|
2019-07-22 23:46:20 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
~LINE();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
static inline bool ClassOf( const ITEM* aItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 16:11:42 +00:00
|
|
|
return aItem && LINE_T == aItem->Kind();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
/// @copydoc ITEM::Clone()
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual LINE* Clone() const override;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2018-09-21 03:15:47 +00:00
|
|
|
LINE& operator=( const LINE& aOther );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-04-15 20:16:24 +00:00
|
|
|
bool IsLinkedChecked() const
|
|
|
|
{
|
|
|
|
return IsLinked() && LinkCount() == SegmentCount();
|
|
|
|
}
|
|
|
|
|
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;
|
2020-01-17 14:19:27 +00:00
|
|
|
m_line.SetWidth( m_width );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///> Returns the shape of the line
|
2020-12-30 19:05:48 +00:00
|
|
|
const SHAPE* Shape() const override { return &m_line; }
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
///> Modifiable accessor to the underlying shape
|
2020-12-30 19:05:48 +00:00
|
|
|
SHAPE_LINE_CHAIN& Line() { return m_line; }
|
|
|
|
const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-12-30 19:05:48 +00:00
|
|
|
int SegmentCount() const { return m_line.SegmentCount(); }
|
|
|
|
int PointCount() const { return m_line.PointCount(); }
|
|
|
|
int ArcCount() const { return m_line.ArcCount(); }
|
2021-01-04 02:37:24 +00:00
|
|
|
int ShapeCount() const { return m_line.ShapeCount(); }
|
2019-05-17 00:13:21 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Returns the aIdx-th point of the line
|
2020-12-30 19:05:48 +00:00
|
|
|
const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
|
|
|
|
const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
|
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;
|
2020-01-17 14:19:27 +00:00
|
|
|
m_line.SetWidth( 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
|
2020-12-30 19:05:48 +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
|
2016-08-29 17:31:13 +00:00
|
|
|
bool CompareGeometry( const LINE& aOther );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
///> Reverses the point/vertex order
|
|
|
|
void Reverse();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
///> Clips the line to the nearest obstacle, traversing from the line's start vertex (0).
|
|
|
|
///> Returns the clipped line.
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE ClipToNearestObstacle( NODE* aNode ) const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
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.
|
2016-08-29 18:36:05 +00:00
|
|
|
int CountCorners( int aAngles ) const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-12-30 19:05:48 +00:00
|
|
|
///> Calculates a line thightly wrapping a convex hull of an obstacle object (aObstacle).
|
2013-09-26 21:53:54 +00:00
|
|
|
///> 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.
|
2020-12-30 19:05:48 +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
|
|
|
|
2020-12-30 19:05:48 +00:00
|
|
|
bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 18:36:05 +00:00
|
|
|
bool Is45Degree() const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> Prints out all linked segments
|
2016-08-29 18:36:05 +00:00
|
|
|
void ShowLinks() const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
bool EndsWithVia() const { return m_hasVia; }
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void AppendVia( const VIA& aVia );
|
2013-09-26 21:53:54 +00:00
|
|
|
void RemoveVia() { m_hasVia = false; }
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const VIA& Via() const { return m_via; }
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2020-12-11 17:54:55 +00:00
|
|
|
void SetViaDiameter( int aDiameter ) { m_via.SetDiameter( aDiameter ); }
|
|
|
|
void SetViaDrill( int aDrill ) { m_via.SetDrill( aDrill ); }
|
|
|
|
|
2020-10-05 19:54:12 +00:00
|
|
|
virtual void Mark( int aMarker ) const override;
|
|
|
|
virtual void Unmark( int aMarker = -1 ) const override;
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual int Marker() const override;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-01-01 17:17:55 +00:00
|
|
|
void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
|
|
|
|
ITEM* GetBlockingObstacle() const { return m_blockingObstacle; }
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
|
|
|
|
void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
void SetRank( int aRank ) override;
|
|
|
|
int Rank() const override;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool HasLoops() const;
|
2016-08-15 15:16:48 +00:00
|
|
|
bool HasLockedSegments() const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2020-02-19 17:22:09 +00:00
|
|
|
void Clear();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OPT_BOX2I ChangedArea( const LINE* aOther ) const;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
void SetSnapThreshhold( int aThreshhold )
|
|
|
|
{
|
|
|
|
m_snapThreshhold = aThreshhold;
|
|
|
|
}
|
2017-08-03 15:53:07 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
int GetSnapThreshhold() const
|
|
|
|
{
|
|
|
|
return m_snapThreshhold;
|
|
|
|
}
|
2017-08-03 15:53:07 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
private:
|
|
|
|
void dragSegment45( const VECTOR2I& aP, int aIndex );
|
|
|
|
void dragCorner45( const VECTOR2I& aP, int aIndex );
|
|
|
|
void dragSegmentFree( const VECTOR2I& aP, int aIndex );
|
|
|
|
void dragCornerFree( const VECTOR2I& aP, int aIndex );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2020-12-30 19:05:48 +00:00
|
|
|
VECTOR2I snapToNeighbourSegments( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
|
|
|
|
int aIndex ) const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-12-30 19:05:48 +00:00
|
|
|
VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
|
|
|
|
int aIndex ) const;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 17:17:55 +00:00
|
|
|
SHAPE_LINE_CHAIN m_line; ///> The actual shape of the line.
|
|
|
|
int m_width; ///> Our width.
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2021-01-01 17:17:55 +00:00
|
|
|
int m_snapThreshhold; ///> Width to smooth out jagged segments.
|
2019-05-17 00:13:21 +00:00
|
|
|
|
2021-01-01 17:17:55 +00:00
|
|
|
bool m_hasVia; ///> Optional via at the end point.
|
2020-12-30 19:05:48 +00:00
|
|
|
VIA m_via;
|
2021-01-01 17:17:55 +00:00
|
|
|
|
|
|
|
ITEM* m_blockingObstacle; ///> For mark obstacle mode.
|
2013-09-26 21:53:54 +00:00
|
|
|
};
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
#endif // __PNS_LINE_H
|