KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_diff_pair_placer.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright The 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
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef __PNS_DIFF_PLACER_H
24#define __PNS_DIFF_PLACER_H
25
26#include <math/vector2d.h>
27
28#include "pns_sizes_settings.h"
29#include "pns_node.h"
30#include "pns_via.h"
31#include "pns_line.h"
32#include "pns_algo_base.h"
33#include "pns_diff_pair.h"
34
35#include "pns_placement_algo.h"
36
37namespace PNS {
38
39class ROUTER;
40class SHOVE;
41class OPTIMIZER;
42class VIA;
43class SIZES_SETTINGS;
44
45
51
53{
54public:
55 DIFF_PAIR_PLACER( ROUTER* aRouter );
57
58 bool FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, ITEM* aItem,
59 DP_PRIMITIVE_PAIR& aPair, wxString* aErrorMsg = nullptr );
60
64 bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
65
70 bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
71
80 bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
81
83 bool CommitPlacement() override;
84
86 bool AbortPlacement() override;
87
89 bool HasPlacedAnything() const override;
90
94 bool ToggleVia( bool aEnabled ) override;
95
99 bool SetLayer( int aLayer ) override;
100
104 const ITEM_SET Traces() override;
105
109 const VECTOR2I& CurrentStart() const override
110 {
111 return m_currentStart;
112 }
113
118 const VECTOR2I& CurrentEnd() const override
119 {
120 return m_currentEnd;
121 }
122
126 const std::vector<NET_HANDLE> CurrentNets() const override;
127
131 int CurrentLayer() const override
132 {
133 return m_currentLayer;
134 }
135
139 NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
140
144 void FlipPosture() override;
145
151 void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
152
153 bool IsPlacingVia() const override { return m_placingVia; }
154
155 void SetOrthoMode( bool aOrthoMode ) override;
156
157 void GetModifiedNets( std::vector<NET_HANDLE>& aNets ) const override;
158
159 const DIFF_PAIR CurrentTrace() const { return m_currentTrace; }
160
161
162private:
163 static constexpr int DP_DEFAULT_GAP_EPSILON = 1000;
164
165
166 int viaGap() const;
167 int gap() const;
168
179 bool route( const VECTOR2I& aP );
180
186
190 void setWorld( NODE* aWorld );
191
195 void initPlacement( );
196
202 void setInitialDirection( const DIRECTION_45& aDirection );
203
204
205 bool routeHead( const VECTOR2I& aP );
206 bool tryWalkDp( NODE* aNode, DIFF_PAIR& aPair, bool aSolidsOnly );
207
209 bool rhWalkOnly( const VECTOR2I& aP );
210
212 bool rhShoveOnly ( const VECTOR2I& aP );
213
215 bool rhMarkObstacles( const VECTOR2I& aP );
216
217 const VIA makeVia ( const VECTOR2I& aP, NET_HANDLE aNet );
218
219 bool attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent, DIFF_PAIR& aWalk, bool aPFirst,
220 bool aWindCw, bool aSolidsOnly );
221 bool propagateDpHeadForces ( const VECTOR2I& aP, VECTOR2I& aNewP );
222
223 bool findDpEndingPrimitives( NODE* aWorld, const VECTOR2I& aP, ITEM* aStartItem,
224 DP_PRIMITIVE_PAIR& aPair, wxString* aErrorMsg );
225
226 bool findDpMidtraceIntersection( NODE* aWorld, const VECTOR2I& aP,
227 ITEM* aStartItem, DP_PRIMITIVE_PAIR& aPair,
228 wxString* aErrorMsg );
229 enum State {
233 };
234
236
241
243
245 std::optional<DP_PRIMITIVE_PAIR> m_prevPair;
246
249
252
255
257 std::unique_ptr<SHOVE> m_shove;
258
261
265
267
270
273
276
279
281
285
288 std::optional<DP_PRIMITIVE_PAIR> m_target;
290
292
293 bool m_idle;
295};
296
297}
298
299#endif // __PNS_LINE_PLACER_H
Represent route directions & corner angles in a 45-degree metric.
Definition direction45.h:37
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Return the most recent world state.
void SetOrthoMode(bool aOrthoMode) override
Function SetOrthoMode()
bool HasPlacedAnything() const override
NODE * m_world
current routing start point (end of tail, beginning of head)
bool tryWalkDp(NODE *aNode, DIFF_PAIR &aPair, bool aSolidsOnly)
route step, walk around mode
bool propagateDpHeadForces(const VECTOR2I &aP, VECTOR2I &aNewP)
bool rhMarkObstacles(const VECTOR2I &aP)
void setInitialDirection(const DIRECTION_45 &aDirection)
Set preferred direction of the very first track segment to be laid.
int m_viaDiameter
current via drill
static constexpr int DP_DEFAULT_GAP_EPSILON
VECTOR2I m_p_start
The shove engine.
std::optional< DP_PRIMITIVE_PAIR > m_prevPair
current algorithm iteration
bool ToggleVia(bool aEnabled) override
Enable/disable a via at the end of currently routed trace.
bool route(const VECTOR2I &aP)
Re-route the current track to point aP.
int m_iteration
pointer to world to search colliding items
const VECTOR2I & CurrentStart() const override
Return the current start of the line being placed.
bool rhShoveOnly(const VECTOR2I &aP)
route step, mark obstacles mode
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Start routing a single track at point aP, taking item aStartItem as anchor (unless NULL).
bool findDpEndingPrimitives(NODE *aWorld, const VECTOR2I &aP, ITEM *aStartItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg)
const ITEM_SET Traces() override
Return the complete routed line, as a single-member ITEM_SET.
void GetModifiedNets(std::vector< NET_HANDLE > &aNets) const override
Function GetModifiedNets.
int m_viaDrill
current track width
const DIFF_PAIR CurrentTrace() const
void FlipPosture() override
Toggle the current posture (straight/diagonal) of the trace head.
DIFF_PAIR_PLACER(ROUTER *aRouter)
bool findDpMidtraceIntersection(NODE *aWorld, const VECTOR2I &aP, ITEM *aStartItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg)
bool attemptWalk(NODE *aNode, DIFF_PAIR *aCurrent, DIFF_PAIR &aWalk, bool aPFirst, bool aWindCw, bool aSolidsOnly)
void setWorld(NODE *aWorld)
Set the board to route.
NODE * m_currentNode
Postprocessed world state (including marked collisions & removed loops)
void initPlacement()
Initialize placement of a new line with given parameters.
const std::vector< NET_HANDLE > CurrentNets() const override
Return the net of currently routed track.
std::optional< DP_PRIMITIVE_PAIR > m_target
bool routeHead(const VECTOR2I &aP)
void UpdateSizes(const SIZES_SETTINGS &aSizes) override
Perform on-the-fly update of the width, via diameter & drill size from a settings class.
bool FindDpPrimitivePair(NODE *aWorld, const VECTOR2I &aP, ITEM *aItem, DP_PRIMITIVE_PAIR &aPair, wxString *aErrorMsg=nullptr)
bool rhWalkOnly(const VECTOR2I &aP)
route step, shove mode
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Move the end of the currently routed trace to the point aP, taking aEndItem as anchor (if not NULL).
bool IsPlacingVia() const override
Function IsPlacingVia()
bool FixRoute(const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish) override
Commit the currently routed track to the parent node, taking aP as the final end point and aEndItem a...
int CurrentLayer() const override
Return the layer of currently routed track.
bool m_placingVia
current via diameter
void updateLeadingRatLine()
Draw the "leading" ratsnest line, which connects the end of currently routed track and the nearest ye...
const VIA makeVia(const VECTOR2I &aP, NET_HANDLE aNet)
SIZES_SETTINGS m_sizes
Are we placing a via?
bool SetLayer(int aLayer) override
Set the current routing layer.
std::unique_ptr< SHOVE > m_shove
Current world state.
const VECTOR2I & CurrentEnd() const override
Return the current end of the line being placed.
Basic class for a differential pair.
Store starting/ending primitives (pads, vias or segments) for a differential pair.
Base class for PNS router board items.
Definition pns_item.h:98
Keep the router "world" - i.e.
Definition pns_node.h:243
Perform various optimizations of the lines being routed, attempting to make the lines shorter and les...
PLACEMENT_ALGO(ROUTER *aRouter)
The actual Push and Shove algorithm.
Definition pns_shove.h:47
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition pns_item.h:55
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683