Horizon
Loading...
Searching...
No Matches
pns_line.h
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2017 CERN
5 * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __PNS_LINE_H
24#define __PNS_LINE_H
25
26#include <math/box2.h>
27#include <math/vector2d.h>
28
29#include <geometry/direction45.h>
30#include <geometry/seg.h>
31#include <geometry/shape.h>
32#include <geometry/shape_line_chain.h>
33
34#include "pns_item.h"
35#include "pns_via.h"
36#include "pns_link_holder.h"
37
38namespace PNS {
39
40class LINKED_ITEM;
41class NODE;
42class VIA;
43
44#define PNS_HULL_MARGIN 10
45
60class LINE : public LINK_HOLDER
61{
62public:
66 LINE() :
67 LINK_HOLDER( LINE_T ),
68 m_blockingObstacle( nullptr )
69 {
70 m_hasVia = false;
71 m_width = 1; // Dummy value
72 m_snapThreshhold = 0;
73 }
74
75 LINE( const LINE& aOther );
76
80 LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
81 LINK_HOLDER( aBase ),
82 m_line( aLine ),
83 m_width( aBase.m_width ),
84 m_snapThreshhold( aBase.m_snapThreshhold ),
85 m_blockingObstacle( nullptr )
86 {
87 m_net = aBase.m_net;
88 m_layers = aBase.m_layers;
89 m_hasVia = false;
90 }
91
95 LINE( const VIA& aVia ) :
96 LINK_HOLDER( LINE_T ),
97 m_blockingObstacle( nullptr )
98 {
99 m_hasVia = true;
100 m_via = aVia;
101 m_width = aVia.Diameter();
102 m_net = aVia.Net();
103 m_layers = aVia.Layers();
104 m_rank = aVia.Rank();
105 m_snapThreshhold = 0;
106 }
107
108 ~LINE();
109
110 static inline bool ClassOf( const ITEM* aItem )
111 {
112 return aItem && LINE_T == aItem->Kind();
113 }
114
116 virtual LINE* Clone() const override;
117
118 LINE& operator=( const LINE& aOther );
119
120 bool IsLinkedChecked() const
121 {
122 return IsLinked() && LinkCount() == ShapeCount();
123 }
124
126 void SetShape( const SHAPE_LINE_CHAIN& aLine )
127 {
128 m_line = aLine;
129 m_line.SetWidth( m_width );
130 }
131
133 const SHAPE* Shape() const override { return &m_line; }
134
136 SHAPE_LINE_CHAIN& Line() { return m_line; }
137 const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
138
139 int SegmentCount() const { return m_line.SegmentCount(); }
140 int PointCount() const { return m_line.PointCount(); }
141 int ArcCount() const { return m_line.ArcCount(); }
142 int ShapeCount() const { return m_line.ShapeCount(); }
143
145 const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
146 const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
147
149 void SetWidth( int aWidth )
150 {
151 m_width = aWidth;
152 m_line.SetWidth( aWidth );
153 }
154
156 int Width() const { return m_width; }
157
159 bool CompareGeometry( const LINE& aOther );
160
162 void Reverse();
163
166 const LINE ClipToNearestObstacle( NODE* aNode ) const;
167
169 void ClipVertexRange ( int aStart, int aEnd );
170
172 int CountCorners( int aAngles ) const;
173
182 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
183
184 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
185
186 bool Is45Degree() const;
187
189 void ShowLinks() const;
190
191 bool EndsWithVia() const { return m_hasVia; }
192
193 void AppendVia( const VIA& aVia );
194 void RemoveVia() { m_hasVia = false; }
195
196 const VIA& Via() const { return m_via; }
197
198 void SetViaDiameter( int aDiameter ) { m_via.SetDiameter( aDiameter ); }
199 void SetViaDrill( int aDrill ) { m_via.SetDrill( aDrill ); }
200
201 virtual void Mark( int aMarker ) const override;
202 virtual void Unmark( int aMarker = -1 ) const override;
203 virtual int Marker() const override;
204
205 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
206 ITEM* GetBlockingObstacle() const { return m_blockingObstacle; }
207
208 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
209 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
210
211 void SetRank( int aRank ) override;
212 int Rank() const override;
213
214 bool HasLoops() const;
215 bool HasLockedSegments() const;
216
217 void Clear();
218
219 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
220
221 void SetSnapThreshhold( int aThreshhold )
222 {
223 m_snapThreshhold = aThreshhold;
224 }
225
226 int GetSnapThreshhold() const
227 {
228 return m_snapThreshhold;
229 }
230
231private:
232 void dragSegment45( const VECTOR2I& aP, int aIndex );
233 void dragCorner45( const VECTOR2I& aP, int aIndex );
234 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
235 void dragCornerFree( const VECTOR2I& aP, int aIndex );
236
237 VECTOR2I snapToNeighbourSegments( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
238 int aIndex ) const;
239
240 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
241 int aIndex ) const;
242
243 SHAPE_LINE_CHAIN m_line;
244 int m_width;
245
246
247 int m_snapThreshhold;
248
249 bool m_hasVia;
250 VIA m_via;
251
252 ITEM* m_blockingObstacle;
253};
254
255}
256
257#endif // __PNS_LINE_H
Base class for PNS router board items.
Definition pns_item.h:57
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:131
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:61
LINE(const VIA &aVia)
Construct a LINE for a lone VIA (ie a stitching via).
Definition pns_line.h:95
const SHAPE * Shape() const override
Modifiable accessor to the underlying shape.
Definition pns_line.h:133
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
Definition pns_line.h:126
void ClipVertexRange(int aStart, int aEnd)
Return the number of corners of angles specified by mask aAngles.
Definition pns_line.cpp:1088
LINE(const LINE &aBase, const SHAPE_LINE_CHAIN &aLine)
Copy properties (net, layers, etc.) from a base line and replaces the shape by another.
Definition pns_line.h:80
LINE()
Makes an empty line.
Definition pns_line.h:66
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:81
void Reverse()
Clip the line to the nearest obstacle, traversing from the line's start vertex (0).
Definition pns_line.cpp:1038
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to a given range of vertices.
Definition pns_line.cpp:566
bool IsLinkedChecked() const
Assign a shape to the line (a polyline/line chain).
Definition pns_line.h:120
bool Is45Degree() const
Print out all linked segments.
Definition pns_line.cpp:537
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
Definition pns_line.cpp:1032
int ShapeCount() const
Return the aIdx-th point of the line.
Definition pns_line.h:142
void SetWidth(int aWidth)
Return line width.
Definition pns_line.h:149
bool Walkaround(SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN &aPre, SHAPE_LINE_CHAIN &aWalk, SHAPE_LINE_CHAIN &aPost, bool aCw) const
Calculate a line tightly wrapping a convex hull of an obstacle object (aObstacle).
const SEG CSegment(int aIdx) const
Set line width.
Definition pns_line.h:146
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition pns_line.h:156
Keep the router "world" - i.e.
Definition pns_node.h:148
Definition pns_via.h:49
Definition seg.h:41
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Definition shape_line_chain.h:81
int ShapeCount() const
Return the number of shapes (line segments or arcs) in this line chain.
Definition shape_line_chain.cpp:903
int PointCount() const
Return the number of points (vertices) in this line chain.
Definition shape_line_chain.h:318
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Definition shape_line_chain.h:393
int SegmentCount() const
Return the number of segments in this line chain.
Definition shape_line_chain.h:295
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
Definition shape_line_chain.h:348
void SetWidth(int aWidth)
Set the width of all segments in the chain.
Definition shape_line_chain.h:275
An abstract shape on 2D plane.
Definition shape.h:117