2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-18 17:55:16 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PNS_SHOVE_H
|
|
|
|
#define __PNS_SHOVE_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <stack>
|
|
|
|
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/box2.h>
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_optimizer.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_routing_settings.h"
|
|
|
|
#include "pns_algo_base.h"
|
|
|
|
#include "pns_logger.h"
|
|
|
|
#include "range.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class LINE;
|
|
|
|
class NODE;
|
|
|
|
class ROUTER;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
2014-11-14 19:19:00 +00:00
|
|
|
* The actual Push and Shove algorithm.
|
2014-05-14 13:53:54 +00:00
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
class SHOVE : public ALGO_BASE
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
enum SHOVE_STATUS
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
SH_OK = 0,
|
|
|
|
SH_NULL,
|
2014-05-14 13:53:54 +00:00
|
|
|
SH_INCOMPLETE,
|
2015-08-19 16:07:16 +00:00
|
|
|
SH_HEAD_MODIFIED,
|
|
|
|
SH_TRY_WALK
|
2013-09-26 21:53:54 +00:00
|
|
|
};
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE( NODE* aWorld, ROUTER* aRouter );
|
|
|
|
~SHOVE();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
virtual LOGGER* Logger() override
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
return &m_logger;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE_STATUS ShoveLines( const LINE& aCurrentHead );
|
|
|
|
SHOVE_STATUS ShoveMultiLines( const ITEM_SET& aHeadSet );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
SHOVE_STATUS ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere,
|
|
|
|
VIA_HANDLE& aNewVia );
|
|
|
|
SHOVE_STATUS ShoveObstacleLine( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
LINE& aResultLine );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
void ForceClearance ( bool aEnabled, int aClearance )
|
|
|
|
{
|
|
|
|
if( aEnabled )
|
|
|
|
m_forceClearance = aClearance;
|
|
|
|
else
|
|
|
|
m_forceClearance = -1;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* CurrentNode();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE NewHead() const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void SetInitialLine( LINE& aInitial );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
bool AddLockedSpringbackNode( NODE* aNode );
|
|
|
|
void UnlockSpringbackNode( NODE* aNode );
|
|
|
|
bool RewindSpringbackTo( NODE* aNode );
|
2021-11-09 05:00:54 +00:00
|
|
|
bool RewindToLastLockedNode();
|
2021-11-21 21:56:26 +00:00
|
|
|
void DisablePostShoveOptimizations( int aMask );
|
2022-08-29 20:21:46 +00:00
|
|
|
void SetSpringbackDoNotTouchNode( const NODE *aNode );
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
private:
|
2014-05-16 11:37:31 +00:00
|
|
|
typedef std::vector<SHAPE_LINE_CHAIN> HULL_SET;
|
2022-08-25 22:50:47 +00:00
|
|
|
typedef std::optional<LINE> OPT_LINE;
|
2016-08-29 17:31:13 +00:00
|
|
|
typedef std::pair<LINE, LINE> LINE_PAIR;
|
2014-05-16 11:37:31 +00:00
|
|
|
typedef std::vector<LINE_PAIR> LINE_PAIR_VEC;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
struct SPRINGBACK_TAG
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-04-21 10:47:48 +00:00
|
|
|
SPRINGBACK_TAG() :
|
|
|
|
m_length( 0 ),
|
2021-05-30 23:47:57 +00:00
|
|
|
m_draggedVia(),
|
2020-04-21 10:47:48 +00:00
|
|
|
m_node( nullptr ),
|
|
|
|
m_seq( 0 ),
|
|
|
|
m_locked( false )
|
|
|
|
{}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
int64_t m_length;
|
2019-08-07 21:48:09 +00:00
|
|
|
VIA_HANDLE m_draggedVia;
|
2014-05-16 11:37:31 +00:00
|
|
|
VECTOR2I m_p;
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_node;
|
2015-02-18 00:29:54 +00:00
|
|
|
OPT_BOX2I m_affectedArea;
|
2020-02-07 19:57:24 +00:00
|
|
|
int m_seq;
|
|
|
|
bool m_locked;
|
2013-09-26 21:53:54 +00:00
|
|
|
};
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE_STATUS shoveLineToHullSet( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
LINE& aResultLine, const HULL_SET& aHulls );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
NODE* reduceSpringback( const ITEM_SET& aHeadSet, VIA_HANDLE& aDraggedVia );
|
|
|
|
|
2019-07-22 23:46:20 +00:00
|
|
|
bool pushSpringback( NODE* aNode, const OPT_BOX2I& aAffectedArea, VIA* aDraggedVia );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE_STATUS shoveLineFromLoneVia( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
LINE& aResultLine );
|
|
|
|
bool checkShoveDirection( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
const LINE& aShovedLine ) const;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
SHOVE_STATUS onCollidingArc( LINE& aCurrent, ARC* aObstacleArc );
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE_STATUS onCollidingLine( LINE& aCurrent, LINE& aObstacle );
|
|
|
|
SHOVE_STATUS onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacleSeg );
|
2022-03-12 23:45:17 +00:00
|
|
|
SHOVE_STATUS onCollidingSolid( LINE& aCurrent, ITEM* aObstacle, OBSTACLE& aObstacleInfo );
|
|
|
|
SHOVE_STATUS onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia, OBSTACLE& aObstacleInfo );
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE_STATUS onReverseCollidingVia( LINE& aCurrent, VIA* aObstacleVia );
|
2019-07-23 23:28:29 +00:00
|
|
|
SHOVE_STATUS pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, int aCurrentRank );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
OPT_BOX2I totalAffectedArea() const;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
void unwindLineStack( const LINKED_ITEM* aSeg );
|
|
|
|
void unwindLineStack( const ITEM* aItem );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void runOptimizer( NODE* aNode );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
bool pushLineStack( const LINE& aL, bool aKeepCurrentOnTop = false );
|
|
|
|
void popLineStack();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
LINE assembleLine( const LINKED_ITEM* aSeg, int* aIndex = nullptr );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew );
|
2021-07-19 23:56:05 +00:00
|
|
|
void replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea = true,
|
|
|
|
NODE *aNode = nullptr );
|
2021-04-26 22:27:30 +00:00
|
|
|
|
|
|
|
LINE* findRootLine( LINE *aLine );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
OPT_BOX2I m_affectedArea;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS shoveIteration( int aIter );
|
2014-11-14 19:19:00 +00:00
|
|
|
SHOVE_STATUS shoveMainLoop();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int getClearance( const ITEM* aA, const ITEM* aB ) const;
|
2021-01-01 00:29:05 +00:00
|
|
|
int getHoleClearance( const ITEM* aA, const ITEM* aB ) const;
|
2022-03-12 23:45:17 +00:00
|
|
|
bool fixupViaCollisions( const LINE* aCurrent, OBSTACLE& obs );
|
2021-07-19 23:56:05 +00:00
|
|
|
void sanityCheck( LINE* aOld, LINE* aNew );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
std::vector<SPRINGBACK_TAG> m_nodeStack;
|
2016-08-29 17:31:13 +00:00
|
|
|
std::vector<LINE> m_lineStack;
|
|
|
|
std::vector<LINE> m_optimizerQueue;
|
2021-04-26 22:27:30 +00:00
|
|
|
std::unordered_map<const LINKED_ITEM*, LINE*> m_rootLineHistory;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_root;
|
|
|
|
NODE* m_currentNode;
|
2022-08-29 20:21:46 +00:00
|
|
|
const NODE* m_springbackDoNotTouchNode;
|
2020-02-07 19:57:24 +00:00
|
|
|
int m_restrictSpringbackTagId;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-04-20 14:59:25 +00:00
|
|
|
OPT_LINE m_newHead;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LOGGER m_logger;
|
|
|
|
VIA* m_draggedVia;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
int m_iter;
|
2015-02-18 00:29:54 +00:00
|
|
|
int m_forceClearance;
|
|
|
|
bool m_multiLineMode;
|
2021-11-21 21:56:26 +00:00
|
|
|
|
|
|
|
int m_optFlagDisableMask;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif // __PNS_SHOVE_H
|