KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_line.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2017 CERN
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Author: Tomasz Wlostowski <[email protected]>
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
30#include <geometry/seg.h>
31#include <geometry/shape.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() :
68 m_blockingObstacle( nullptr )
69 {
70 m_width = 1; // Dummy value
72 m_via = nullptr;
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 ),
85 m_blockingObstacle( nullptr )
86 {
87 m_net = aBase.m_net;
88 m_layers = aBase.m_layers;
89 m_via = nullptr;
90 }
91
95 LINE( const VIA& aVia ) :
97 m_blockingObstacle( nullptr )
98 {
99 m_via = aVia.Clone();
100 m_width = aVia.Diameter();
101 m_net = aVia.Net();
102 m_layers = aVia.Layers();
103 m_rank = aVia.Rank();
105 }
106
107 ~LINE();
108
109 static inline bool ClassOf( const ITEM* aItem )
110 {
111 return aItem && LINE_T == aItem->Kind();
112 }
113
115 virtual LINE* Clone() const override;
116
117 LINE& operator=( const LINE& aOther );
118
119 bool IsLinkedChecked() const
120 {
121 return IsLinked() && LinkCount() == ShapeCount();
122 }
123
125 void SetShape( const SHAPE_LINE_CHAIN& aLine )
126 {
127 m_line = aLine;
129 }
130
132 const SHAPE* Shape() const override { return &m_line; }
133
136 const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
137
138 int SegmentCount() const { return m_line.SegmentCount(); }
139 int PointCount() const { return m_line.PointCount(); }
140 int ArcCount() const { return m_line.ArcCount(); }
141 int ShapeCount() const { return m_line.ShapeCount(); }
142
144 const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
145 const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
146
148 void SetWidth( int aWidth )
149 {
150 m_width = aWidth;
151 m_line.SetWidth( aWidth );
152 }
153
155 int Width() const { return m_width; }
156
158 bool CompareGeometry( const LINE& aOther );
159
161 void Reverse();
162
165 const LINE ClipToNearestObstacle( NODE* aNode ) const;
166
168 void ClipVertexRange ( int aStart, int aEnd );
169
171 int CountCorners( int aAngles ) const;
172
181 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
182
183 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
184
186 void ShowLinks() const;
187
188 bool EndsWithVia() const { return m_via != nullptr; }
189
190 void AppendVia( const VIA& aVia );
191 void RemoveVia();
192
193 VIA& Via() { return *m_via; }
194 const VIA& Via() const { return *m_via; }
195
196 void SetViaDiameter( int aDiameter ) { assert(m_via); m_via->SetDiameter( aDiameter ); }
197 void SetViaDrill( int aDrill ) { assert(m_via); m_via->SetDrill( aDrill ); }
198
199 virtual void Mark( int aMarker ) const override;
200 virtual void Unmark( int aMarker = -1 ) const override;
201 virtual int Marker() const override;
202
203 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
205
206 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
207 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
208
209 void SetRank( int aRank ) override;
210 int Rank() const override;
211
212 bool HasLoops() const;
213 bool HasLockedSegments() const;
214
215 void Clear();
216
217 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
218
219 void SetSnapThreshhold( int aThreshhold )
220 {
221 m_snapThreshhold = aThreshhold;
222 }
223
225 {
226 return m_snapThreshhold;
227 }
228
229private:
230 void dragSegment45( const VECTOR2I& aP, int aIndex );
231 void dragCorner45( const VECTOR2I& aP, int aIndex );
232 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
233 void dragCornerFree( const VECTOR2I& aP, int aIndex );
234
236 int aIndex ) const;
237
238 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
239 int aIndex ) const;
240
243
244
246
248
250};
251
252}
253
254#endif // __PNS_LINE_H
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:890
Base class for PNS router board items.
Definition: pns_item.h:97
virtual int Rank() const
Definition: pns_item.h:234
virtual NET_HANDLE Net() const
Definition: pns_item.h:193
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:166
LAYER_RANGE m_layers
Definition: pns_item.h:287
NET_HANDLE m_net
Definition: pns_item.h:290
const LAYER_RANGE & Layers() const
Definition: pns_item.h:195
int m_rank
Definition: pns_item.h:292
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
void SetViaDrill(int aDrill)
Definition: pns_line.h:197
virtual void Unmark(int aMarker=-1) const override
Definition: pns_line.cpp:119
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:867
const VECTOR2I & CPoint(int aIdx) const
Definition: pns_line.h:144
ITEM * GetBlockingObstacle() const
Definition: pns_line.h:204
LINE(const VIA &aVia)
Construct a LINE for a lone VIA (ie a stitching via).
Definition: pns_line.h:95
int ArcCount() const
Definition: pns_line.h:140
const SHAPE * Shape() const override
Modifiable accessor to the underlying shape.
Definition: pns_line.h:132
VIA * m_via
Definition: pns_line.h:247
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
Definition: pns_line.h:125
int m_width
Our width.
Definition: pns_line.h:242
virtual void Mark(int aMarker) const override
Definition: pns_line.cpp:109
void ClipVertexRange(int aStart, int aEnd)
Return the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:1094
void RemoveVia()
Definition: pns_line.cpp:1271
int CountCorners(int aAngles) const
Definition: pns_line.cpp:153
bool HasLoops() const
Definition: pns_line.cpp:1143
const VIA & Via() const
Definition: pns_line.h:194
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition: pns_line.h:249
const SHAPE_LINE_CHAIN & CLine() const
Definition: pns_line.h:136
void SetRank(int aRank) override
Definition: pns_line.cpp:1064
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:1172
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
bool HasLockedSegments() const
Definition: pns_line.cpp:1253
void Clear()
Definition: pns_line.cpp:1264
SHAPE_LINE_CHAIN & Line()
Definition: pns_line.h:135
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition: pns_line.cpp:101
void Reverse()
Clip the line to the nearest obstacle, traversing from the line's start vertex (0).
Definition: pns_line.cpp:1043
void ShowLinks() const
void dragCorner45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:693
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to a given range of vertices.
Definition: pns_line.cpp:566
LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:72
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:754
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:109
VIA & Via()
Definition: pns_line.h:193
void SetSnapThreshhold(int aThreshhold)
Definition: pns_line.h:219
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:822
int SegmentCount() const
Definition: pns_line.h:138
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:768
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
bool IsLinkedChecked() const
Assign a shape to the line (a polyline/line chain).
Definition: pns_line.h:119
void SetViaDiameter(int aDiameter)
Definition: pns_line.h:196
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:780
virtual int Marker() const override
Definition: pns_line.cpp:128
int PointCount() const
Definition: pns_line.h:139
int m_snapThreshhold
Width to smooth out jagged segments.
Definition: pns_line.h:245
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
Definition: pns_line.cpp:1037
int ShapeCount() const
Return the aIdx-th point of the line.
Definition: pns_line.h:141
SHAPE_LINE_CHAIN m_line
The actual shape of the line.
Definition: pns_line.h:241
void AppendVia(const VIA &aVia)
Definition: pns_line.cpp:1051
void SetWidth(int aWidth)
Return line width.
Definition: pns_line.h:148
int GetSnapThreshhold() const
Definition: pns_line.h:224
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).
void SetBlockingObstacle(ITEM *aObstacle)
Definition: pns_line.h:203
bool EndsWithVia() const
Definition: pns_line.h:188
const SEG CSegment(int aIdx) const
Set line width.
Definition: pns_line.h:145
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:155
int Rank() const override
Definition: pns_line.cpp:1074
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:727
Keep the router "world" - i.e.
Definition: pns_node.h:207
int Diameter() const
Definition: pns_via.h:142
void SetDiameter(int aDiameter)
Definition: pns_via.h:144
void SetDrill(int aDrill)
Definition: pns_via.h:152
VIA * Clone() const override
Return a deep copy of the item.
Definition: pns_via.cpp:158
Definition: seg.h:42
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int ShapeCount() const
Return the number of shapes (line segments or arcs) in this line chain.
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
size_t ArcCount() const
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
void SetWidth(int aWidth)
Set the width of all segments in the chain.
An abstract shape on 2D plane.
Definition: shape.h:126
Push and Shove diff pair dimensions (gap) settings dialog.
@ VIA
Normal via.
Definition: router_tool.cpp:93