Horizon
pns_line_placer.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_PLACER_H
24 #define __PNS_LINE_PLACER_H
25 
26 #include <math/vector2d.h>
27 
28 #include <geometry/shape.h>
29 #include <geometry/shape_line_chain.h>
30 
31 #include "pns_line.h"
32 #include "pns_mouse_trail_tracer.h"
33 #include "pns_node.h"
34 #include "pns_placement_algo.h"
35 #include "pns_sizes_settings.h"
36 #include "pns_via.h"
37 
38 namespace PNS {
39 
40 class ROUTER;
41 class SHOVE;
42 class OPTIMIZER;
43 class VIA;
44 class SIZES_SETTINGS;
45 class NODE;
46 
48 {
49 public:
50  FIXED_TAIL( int aLineCount = 1);
51  ~FIXED_TAIL();
52 
53  struct FIX_POINT
54  {
55  int layer;
56  bool placingVias;
57  VECTOR2I p;
58  DIRECTION_45 direction;
59  };
60 
61  struct STAGE
62  {
63  NODE* commit;
64  std::vector<FIX_POINT> pts;
65  };
66 
67  void Clear();
68  void AddStage( const VECTOR2I& aStart, int aLayer, bool placingVias, DIRECTION_45 direction,
69  NODE* aNode );
70  bool PopStage( STAGE& aStage );
71  int StageCount() const;
72 
73 private:
74  std::vector<STAGE> m_stages;
75 };
76 
77 
78 
85 {
86 public:
87  LINE_PLACER( ROUTER* aRouter );
88  ~LINE_PLACER();
89 
93  bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
94 
99  bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
100 
109  bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
110 
111  bool UnfixRoute() override;
112 
113  bool CommitPlacement() override;
114 
115  bool AbortPlacement() override;
116 
117  bool HasPlacedAnything() const override;
118 
122  bool ToggleVia( bool aEnabled ) override;
123 
127  bool SetLayer( int aLayer ) override;
128 
133  const LINE& Head() const { return m_head; }
134 
139  const LINE& Tail() const { return m_tail; }
140 
144  const LINE Trace() const;
145 
149  const ITEM_SET Traces() override;
150 
155  const VECTOR2I& CurrentEnd() const override
156  {
157  return m_currentEnd;
158  }
159 
163  const std::vector<int> CurrentNets() const override
164  {
165  return std::vector<int>( 1, m_currentNet );
166  }
167 
171  int CurrentLayer() const override
172  {
173  return m_currentLayer;
174  }
175 
179  NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
180 
184  void FlipPosture() override;
185 
192  void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
193 
194  void SetOrthoMode( bool aOrthoMode ) override;
195 
196  bool IsPlacingVia() const override { return m_placingVia; }
197 
198  void GetModifiedNets( std::vector<int>& aNets ) const override;
199 
204  bool SplitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
205 
206 private:
215  bool route( const VECTOR2I& aP );
216 
221  void updateLeadingRatLine();
222 
226  void setWorld( NODE* aWorld );
227 
231  void initPlacement();
232 
237  void setInitialDirection( const DIRECTION_45& aDirection );
238 
243  void removeLoops( NODE* aNode, LINE& aLatest );
244 
250  void simplifyNewLine( NODE* aNode, LINKED_ITEM* aLatest );
251 
259  bool handleSelfIntersections();
260 
267  bool handlePullback();
268 
274  bool mergeHead();
275 
284  bool reduceTail( const VECTOR2I& aEnd );
285 
292  bool optimizeTailHeadTransition();
293 
300  bool routeHead( const VECTOR2I& aP, LINE& aNewHead );
301 
308  void routeStep( const VECTOR2I& aP );
309 
311  bool rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead );
312 
314  bool rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead );
315 
317  bool rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead );
318 
319  const VIA makeVia( const VECTOR2I& aP );
320 
321  bool buildInitialLine( const VECTOR2I& aP, LINE& aHead, bool aForceNoVia = false );
322 
323 
324  DIRECTION_45 m_direction;
325  DIRECTION_45 m_initial_direction;
326 
327  LINE m_head;
329 
330  LINE m_last_head;
331 
332  LINE m_tail;
334 
335  NODE* m_world;
336  VECTOR2I m_p_start;
337 
338  std::unique_ptr<SHOVE> m_shove;
339 
340  NODE* m_currentNode;
341  NODE* m_lastNode;
343 
344  SIZES_SETTINGS m_sizes;
345 
346  bool m_placingVia;
347 
348  int m_currentNet;
349  int m_currentLayer;
350 
351  VECTOR2I m_currentEnd;
352  VECTOR2I m_currentStart;
353  LINE m_currentTrace;
354 
355  ITEM* m_startItem;
356  ITEM* m_endItem;
357 
358  bool m_idle;
359  bool m_chainedPlacement;
360  bool m_orthoMode;
361  bool m_placementCorrect;
362 
363  FIXED_TAIL m_fixedTail;
364  MOUSE_TRAIL_TRACER m_mouseTrailTracer;
365 };
366 
367 }
368 
369 #endif // __PNS_LINE_PLACER_H
Represent route directions & corner angles in a 45-degree metric.
Definition: direction45.h:37
Definition: pns_line_placer.h:48
Definition: pns_itemset.h:37
Base class for PNS router board items.
Definition: pns_item.h:57
Single track placement algorithm.
Definition: pns_line_placer.h:85
bool SetLayer(int aLayer) override
Set the current routing layer.
Definition: pns_line_placer.cpp:1080
const LINE Trace() const
Return the complete routed line.
Definition: pns_line_placer.cpp:1019
const VECTOR2I & CurrentEnd() const override
Return the current end of the line being placed.
Definition: pns_line_placer.h:155
void UpdateSizes(const SIZES_SETTINGS &aSizes) override
Perform on-the-fly update of the width, via diameter & drill size from a settings class.
Definition: pns_line_placer.cpp:1650
void SetOrthoMode(bool aOrthoMode) override
Function SetOrthoMode()
Definition: pns_line_placer.cpp:1687
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Start routing a single track at point aP, taking item aStartItem as anchor (unless NULL).
Definition: pns_line_placer.cpp:1115
const LINE & Head() const
Return the "head" of the line being placed, that is the volatile part that has not been "fixed" yet.
Definition: pns_line_placer.h:133
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Return the most recent world state.
Definition: pns_line_placer.cpp:1043
bool SplitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
Check if point aP lies on segment aSeg.
Definition: pns_line_placer.cpp:1052
int CurrentLayer() const override
Return the layer of currently routed track.
Definition: pns_line_placer.h:171
const LINE & Tail() const
Return the "tail" of the line being placed, the part which has already wrapped around and shoved some...
Definition: pns_line_placer.h:139
void FlipPosture() override
Toggle the current posture (straight/diagonal) of the trace head.
Definition: pns_line_placer.cpp:1037
void GetModifiedNets(std::vector< int > &aNets) const override
Function GetModifiedNets.
Definition: pns_line_placer.cpp:1768
const std::vector< int > CurrentNets() const override
Return the net code of currently routed track.
Definition: pns_line_placer.h:163
bool IsPlacingVia() const override
Function IsPlacingVia()
Definition: pns_line_placer.h:196
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).
Definition: pns_line_placer.cpp:1215
const ITEM_SET Traces() override
Return the complete routed line, as a single-member ITEM_SET.
Definition: pns_line_placer.cpp:1030
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 as...
Definition: pns_line_placer.cpp:1261
bool ToggleVia(bool aEnabled) override
Enable/disable a via at the end of currently routed trace.
Definition: pns_line_placer.cpp:82
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
Definition: pns_linked_item.h:30
Definition: pns_mouse_trail_tracer.h:32
Keep the router "world" - i.e.
Definition: pns_node.h:148
PLACEMENT_ALGO.
Definition: pns_placement_algo.h:46
Definition: pns_router.h:116
Definition: pns_sizes_settings.h:42
Definition: pns_via.h:49
Definition: pns_line_placer.h:54
Definition: pns_line_placer.h:62