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 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef __PNS_LINE_PLACER_H
23 #define __PNS_LINE_PLACER_H
24 
25 #include <math/vector2d.h>
26 
27 #include <geometry/shape.h>
28 #include <geometry/shape_line_chain.h>
29 
30 #include "pns_sizes_settings.h"
31 #include "pns_node.h"
32 #include "pns_via.h"
33 #include "pns_line.h"
34 #include "pns_placement_algo.h"
35 
36 namespace PNS {
37 
38 class ROUTER;
39 class SHOVE;
40 class OPTIMIZER;
41 class VIA;
42 class SIZES_SETTINGS;
43 
44 
53 {
54 public:
55  LINE_PLACER( ROUTER* aRouter );
56  ~LINE_PLACER();
57 
64  bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
65 
73  bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
74 
84  bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
85 
91  bool ToggleVia( bool aEnabled ) override;
92 
98  bool SetLayer( int aLayer ) override;
99 
106  const LINE& Head() const { return m_head; }
107 
114  const LINE& Tail() const { return m_tail; }
115 
121  const LINE Trace() const;
122 
128  const ITEM_SET Traces() override;
129 
136  const VECTOR2I& CurrentEnd() const override
137  {
138  return m_currentEnd;
139  }
140 
146  const std::vector<int> CurrentNets() const override
147  {
148  return std::vector<int>( 1, m_currentNet );
149  }
150 
156  int CurrentLayer() const override
157  {
158  return m_currentLayer;
159  }
160 
166  NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
167 
173  void FlipPosture() override;
174 
182  void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
183 
184  void SetOrthoMode( bool aOrthoMode ) override;
185 
186  bool IsPlacingVia() const override { return m_placingVia; }
187 
188  void GetModifiedNets( std::vector<int>& aNets ) const override;
189 
190  LOGGER* Logger() override;
191 
198  bool SplitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
199 
200 
201 private:
212  bool route( const VECTOR2I& aP );
213 
221  void updateLeadingRatLine();
222 
228  void setWorld( NODE* aWorld );
229 
235  void initPlacement();
236 
243  void setInitialDirection( const DIRECTION_45& aDirection );
244 
251  void removeLoops( NODE* aNode, LINE& aLatest );
252 
260  void simplifyNewLine( NODE* aNode, SEGMENT* aLatest );
261 
269  bool checkObtusity( const SEG& aA, const SEG& aB ) const;
270 
279  bool handleSelfIntersections();
280 
288  bool handlePullback();
289 
297  bool mergeHead();
298 
308  bool reduceTail( const VECTOR2I& aEnd );
309 
317  bool optimizeTailHeadTransition();
318 
327  bool routeHead( const VECTOR2I& aP, LINE& aNewHead);
328 
336  void routeStep( const VECTOR2I& aP );
337 
338  const LINE reduceToNearestObstacle( const LINE& aOriginalLine );
339 
340  bool rhStopAtNearestObstacle( const VECTOR2I& aP, LINE& aNewHead );
341 
342 
344  bool rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead);
345 
347  bool rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead);
348 
350  bool rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead );
351 
352  const VIA makeVia( const VECTOR2I& aP );
353 
354  bool buildInitialLine( const VECTOR2I& aP, LINE& aHead, bool aInvertPosture = false );
355 
357  DIRECTION_45 m_direction;
358 
360  DIRECTION_45 m_initial_direction;
361 
364  LINE m_head;
365 
367  LINE m_tail;
368 
370  NODE* m_world;
371 
373  VECTOR2I m_p_start;
374 
376  std::unique_ptr< SHOVE > m_shove;
377 
379  NODE* m_currentNode;
380 
382  NODE* m_lastNode;
383 
384  SIZES_SETTINGS m_sizes;
385 
387  bool m_placingVia;
388 
389  int m_currentNet;
390  int m_currentLayer;
391 
392  VECTOR2I m_currentEnd, m_currentStart;
393  LINE m_currentTrace;
394 
395  PNS_MODE m_currentMode;
396  ITEM* m_startItem;
397 
398  bool m_idle;
399  bool m_chainedPlacement;
400  bool m_orthoMode;
401 };
402 
403 }
404 
405 #endif // __PNS_LINE_PLACER_H
PNS::LINE_PLACER::IsPlacingVia
bool IsPlacingVia() const override
Function IsPlacingVia()
Definition: pns_line_placer.h:186
PNS::LINE
Definition: pns_line.h:60
PNS::LINE_PLACER::SetLayer
bool SetLayer(int aLayer) override
Function SetLayer()
Definition: pns_line_placer.cpp:832
PNS::SIZES_SETTINGS
Definition: pns_sizes_settings.h:37
PNS::LINE_PLACER::Traces
const ITEM_SET Traces() override
Function Traces()
Definition: pns_line_placer.cpp:778
PNS::SEGMENT
Definition: pns_segment.h:38
PNS::LINE_PLACER::Move
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
Definition: pns_line_placer.cpp:914
PNS::LINE_PLACER::CurrentNets
const std::vector< int > CurrentNets() const override
Function CurrentNet()
Definition: pns_line_placer.h:146
PNS::LINE_PLACER::CurrentNode
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Function CurrentNode()
Definition: pns_line_placer.cpp:792
PNS::ROUTER
Definition: pns_router.h:109
PNS::LINE_PLACER::ToggleVia
bool ToggleVia(bool aEnabled) override
Function ToggleVia()
Definition: pns_line_placer.cpp:77
PNS::PLACEMENT_ALGO
Class PLACEMENT_ALGO.
Definition: pns_placement_algo.h:45
PNS::LINE_PLACER::Tail
const LINE & Tail() const
Function Tail()
Definition: pns_line_placer.h:114
PNS::LINE_PLACER::FlipPosture
void FlipPosture() override
Function FlipPosture()
Definition: pns_line_placer.cpp:785
VECTOR2< int >
PNS::LINE_PLACER::CurrentLayer
int CurrentLayer() const override
Function CurrentLayer()
Definition: pns_line_placer.h:156
PNS::VIA
Definition: pns_via.h:37
PNS::LINE_PLACER::FixRoute
bool FixRoute(const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish) override
Function FixRoute()
Definition: pns_line_placer.cpp:954
PNS::LOGGER
Definition: pns_logger.h:39
PNS::LINE_PLACER::CurrentEnd
const VECTOR2I & CurrentEnd() const override
Function CurrentEnd()
Definition: pns_line_placer.h:136
PNS::LINE_PLACER::SetOrthoMode
void SetOrthoMode(bool aOrthoMode) override
Function SetOrthoMode()
Definition: pns_line_placer.cpp:1155
SEG
Definition: seg.h:36
PNS::LINE_PLACER::UpdateSizes
void UpdateSizes(const SIZES_SETTINGS &aSizes) override
Function UpdateSizes()
Definition: pns_line_placer.cpp:1133
PNS::LINE_PLACER::Logger
LOGGER * Logger() override
Returns the logger object, allowing to dump geometry to a file.
Definition: pns_line_placer.cpp:1229
PNS::ITEM_SET
Definition: pns_itemset.h:39
PNS::LINE_PLACER::Trace
const LINE Trace() const
Function Trace()
Definition: pns_line_placer.cpp:767
PNS::LINE_PLACER
Class LINE_PLACER.
Definition: pns_line_placer.h:52
PNS::ITEM
Class ITEM.
Definition: pns_item.h:54
PNS::LINE_PLACER::SplitAdjacentSegments
bool SplitAdjacentSegments(NODE *aNode, ITEM *aSeg, const VECTOR2I &aP)
Function SplitAdjacentSegments()
Definition: pns_line_placer.cpp:801
PNS::NODE
Class NODE.
Definition: pns_node.h:136
DIRECTION_45
Class DIRECTION_45.
Definition: direction45.h:36
PNS::LINE_PLACER::Head
const LINE & Head() const
Function Head()
Definition: pns_line_placer.h:106
PNS::LINE_PLACER::Start
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
Definition: pns_line_placer.cpp:855
PNS::LINE_PLACER::GetModifiedNets
void GetModifiedNets(std::vector< int > &aNets) const override
Function GetModifiedNets.
Definition: pns_line_placer.cpp:1224