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
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 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>
|
|
|
|
|
|
|
|
#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
|
|
|
/**
|
2016-08-29 17:31:13 +00:00
|
|
|
* Class SHOVE
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE_STATUS ShoveDraggingVia( VIA* aVia, const VECTOR2I& aWhere, VIA** aNewVia );
|
|
|
|
SHOVE_STATUS ProcessSingleLine( LINE& aCurrent, LINE& aObstacle,
|
|
|
|
LINE& aShoved );
|
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
|
|
|
|
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;
|
2016-08-29 17:31:13 +00:00
|
|
|
typedef boost::optional<LINE> OPT_LINE;
|
|
|
|
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
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
int64_t m_length;
|
|
|
|
int m_segments;
|
|
|
|
VECTOR2I m_p;
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_node;
|
|
|
|
ITEM_SET m_headItems;
|
|
|
|
COST_ESTIMATOR m_cost;
|
2015-02-18 00:29:54 +00:00
|
|
|
OPT_BOX2I m_affectedArea;
|
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 processHullSet( LINE& aCurrent, LINE& aObstacle,
|
|
|
|
LINE& aShoved, const HULL_SET& hulls );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool reduceSpringback( const ITEM_SET& aHeadItems );
|
|
|
|
bool pushSpringback( NODE* aNode, const ITEM_SET& aHeadItems,
|
|
|
|
const COST_ESTIMATOR& aCost, const OPT_BOX2I& aAffectedArea );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE_STATUS walkaroundLoneVia( LINE& aCurrent, LINE& aObstacle, LINE& aShoved );
|
|
|
|
bool checkBumpDirection( const LINE& aCurrent, const LINE& aShoved ) const;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE_STATUS onCollidingLine( LINE& aCurrent, LINE& aObstacle );
|
|
|
|
SHOVE_STATUS onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacleSeg );
|
|
|
|
SHOVE_STATUS onCollidingSolid( LINE& aCurrent, ITEM* aObstacle );
|
|
|
|
SHOVE_STATUS onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia );
|
|
|
|
SHOVE_STATUS onReverseCollidingVia( LINE& aCurrent, VIA* aObstacleVia );
|
|
|
|
SHOVE_STATUS pushVia( VIA* aVia, const VECTOR2I& aForce, int aCurrentRank, bool aDryRun = false );
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void unwindStack( SEGMENT* aSeg );
|
|
|
|
void unwindStack( 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool pushLine( const LINE& aL, bool aKeepCurrentOnTop = false );
|
2014-11-14 19:19:00 +00:00
|
|
|
void popLine();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE assembleLine( const SEGMENT* aSeg, int* aIndex = NULL );
|
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 );
|
|
|
|
void replaceLine( LINE& aOld, LINE& aNew );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
OPT_BOX2I m_affectedAreaSum;
|
|
|
|
|
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;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
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;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_root;
|
|
|
|
NODE* m_currentNode;
|
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;
|
|
|
|
ITEM_SET m_draggedViaHeadSet;
|
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;
|
2016-08-29 17:31:13 +00:00
|
|
|
void sanityCheck( LINE* aOld, LINE* aNew );
|
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
|