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
|
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
|
|
|
|
|
|
|
class PNS_LINE;
|
|
|
|
class PNS_NODE;
|
|
|
|
class PNS_ROUTER;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Class PNS_SHOVE
|
|
|
|
*
|
2014-11-14 19:19:00 +00:00
|
|
|
* The actual Push and Shove algorithm.
|
2014-05-14 13:53:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class PNS_SHOVE : public PNS_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,
|
|
|
|
SH_HEAD_MODIFIED
|
2013-09-26 21:53:54 +00:00
|
|
|
};
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_SHOVE( PNS_NODE* aWorld, PNS_ROUTER* aRouter );
|
2014-05-14 13:53:54 +00:00
|
|
|
~PNS_SHOVE();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
virtual PNS_LOGGER* Logger()
|
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
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS ShoveLines( const PNS_LINE& aCurrentHead );
|
2015-02-18 00:29:54 +00:00
|
|
|
SHOVE_STATUS ShoveMultiLines( const PNS_ITEMSET& aHeadSet );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS ShoveDraggingVia( PNS_VIA*aVia, const VECTOR2I& aWhere, PNS_VIA** aNewVia );
|
2015-02-18 16:53:46 +00:00
|
|
|
SHOVE_STATUS ProcessSingleLine( PNS_LINE* aCurrent, PNS_LINE* aObstacle,
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_LINE* aShoved );
|
|
|
|
|
|
|
|
void ForceClearance ( bool aEnabled, int aClearance )
|
|
|
|
{
|
|
|
|
if( aEnabled )
|
|
|
|
m_forceClearance = aClearance;
|
|
|
|
else
|
|
|
|
m_forceClearance = -1;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_NODE* CurrentNode();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const PNS_LINE NewHead() const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void SetInitialLine ( PNS_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;
|
|
|
|
typedef boost::optional<PNS_LINE> OPT_LINE;
|
|
|
|
typedef std::pair <PNS_LINE*, PNS_LINE*> LINE_PAIR;
|
|
|
|
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;
|
|
|
|
PNS_NODE* m_node;
|
|
|
|
PNS_ITEMSET m_headItems;
|
|
|
|
PNS_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
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS processHullSet( PNS_LINE* aCurrent, PNS_LINE* aObstacle,
|
|
|
|
PNS_LINE* aShoved, const HULL_SET& hulls );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
bool reduceSpringback( const PNS_ITEMSET& aHeadItems );
|
2015-02-18 00:29:54 +00:00
|
|
|
bool pushSpringback( PNS_NODE* aNode, const PNS_ITEMSET& aHeadItems,
|
|
|
|
const PNS_COST_ESTIMATOR& aCost, const OPT_BOX2I& aAffectedArea );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS walkaroundLoneVia( PNS_LINE* aCurrent, PNS_LINE* aObstacle, PNS_LINE* aShoved );
|
|
|
|
bool checkBumpDirection( PNS_LINE* aCurrent, PNS_LINE* aShoved ) const;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS onCollidingLine( PNS_LINE* aCurrent, PNS_LINE* aObstacle );
|
|
|
|
SHOVE_STATUS onCollidingSegment( PNS_LINE* aCurrent, PNS_SEGMENT* aObstacleSeg );
|
|
|
|
SHOVE_STATUS onCollidingSolid( PNS_LINE* aCurrent, PNS_SOLID* aObstacleSolid );
|
|
|
|
SHOVE_STATUS onCollidingVia( PNS_ITEM* aCurrent, PNS_VIA* aObstacleVia );
|
|
|
|
SHOVE_STATUS onReverseCollidingVia( PNS_LINE* aCurrent, PNS_VIA* aObstacleVia );
|
2015-02-18 00:29:54 +00:00
|
|
|
SHOVE_STATUS pushVia( PNS_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
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void unwindStack( PNS_SEGMENT* aSeg );
|
2014-11-14 19:19:00 +00:00
|
|
|
void unwindStack( PNS_ITEM* aItem );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void runOptimizer( PNS_NODE* aNode, PNS_LINE* aHead );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
void pushLine( PNS_LINE* aL );
|
|
|
|
void popLine();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_LINE* assembleLine( const PNS_SEGMENT* aSeg, int* aIndex = NULL );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
void replaceItems( PNS_ITEM *aOld, PNS_ITEM *aNew );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
template<class T> T* clone ( const T* aItem )
|
|
|
|
{
|
|
|
|
T *cloned = aItem->Clone();
|
|
|
|
|
|
|
|
m_gcItems.push_back( cloned );
|
|
|
|
return cloned;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int getClearance( PNS_ITEM *aA, PNS_ITEM *aB ) const;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
std::vector<SPRINGBACK_TAG> m_nodeStack;
|
2014-05-14 13:53:54 +00:00
|
|
|
std::vector<PNS_LINE*> m_lineStack;
|
|
|
|
std::vector<PNS_LINE*> m_optimizerQueue;
|
|
|
|
std::vector<PNS_ITEM*> m_gcItems;
|
|
|
|
|
|
|
|
PNS_NODE* m_root;
|
|
|
|
PNS_NODE* m_currentNode;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
OPT_LINE m_newHead;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
PNS_LOGGER m_logger;
|
|
|
|
PNS_VIA* m_draggedVia;
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ITEMSET 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;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif // __PNS_SHOVE_H
|