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_WALKAROUND_H
|
|
|
|
#define __PNS_WALKAROUND_H
|
|
|
|
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_node.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_router.h"
|
|
|
|
#include "pns_logger.h"
|
|
|
|
#include "pns_algo_base.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
class PNS_WALKAROUND : public PNS_ALGO_BASE
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
static const int DefaultIterationLimit = 50;
|
|
|
|
|
|
|
|
public:
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_WALKAROUND( PNS_NODE* aWorld, PNS_ROUTER* aRouter ) :
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_ALGO_BASE ( aRouter ),
|
|
|
|
m_world( aWorld ),
|
2014-05-16 11:37:31 +00:00
|
|
|
m_iterationLimit( DefaultIterationLimit )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
m_forceSingleDirection = false;
|
|
|
|
m_forceLongerPath = false;
|
|
|
|
m_cursorApproachMode = false;
|
2014-05-16 11:37:31 +00:00
|
|
|
m_itemMask = PNS_ITEM::ANY;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
~PNS_WALKAROUND() {};
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
enum WALKAROUND_STATUS
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
IN_PROGRESS = 0,
|
|
|
|
DONE,
|
|
|
|
STUCK
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetWorld( PNS_NODE* aNode )
|
|
|
|
{
|
|
|
|
m_world = aNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetIterationLimit( const int aIterLimit )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
m_iterationLimit = aIterLimit;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetSolidsOnly( bool aSolidsOnly )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aSolidsOnly )
|
|
|
|
m_itemMask = PNS_ITEM::SOLID;
|
2014-05-14 13:53:54 +00:00
|
|
|
else
|
2014-05-16 11:37:31 +00:00
|
|
|
m_itemMask = PNS_ITEM::ANY;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void SetItemMask( int aMask )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
m_itemMask = aMask;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void SetSingleDirection( bool aForceSingleDirection )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
m_forceSingleDirection = aForceSingleDirection;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_forceLongerPath = aForceSingleDirection;
|
|
|
|
//printf("FSD %d FPD %d\n", m_forceSingleDirection?1:0, m_forceLongerPath ? 1: 0);
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetApproachCursor( bool aEnabled, const VECTOR2I& aPos )
|
|
|
|
{
|
|
|
|
m_cursorPos = aPos;
|
|
|
|
m_cursorApproachMode = aEnabled;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
WALKAROUND_STATUS Route( const PNS_LINE& aInitialPath, PNS_LINE& aWalkPath,
|
2013-09-26 21:53:54 +00:00
|
|
|
bool aOptimize = true );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
virtual PNS_LOGGER* Logger()
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
return &m_logger;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
private:
|
|
|
|
void start( const PNS_LINE& aInitialPath );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
WALKAROUND_STATUS singleStep( PNS_LINE& aPath, bool aWindingDirection );
|
|
|
|
PNS_NODE::OPT_OBSTACLE nearestObstacle( const PNS_LINE& aPath );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
PNS_NODE* m_world;
|
|
|
|
|
|
|
|
int m_recursiveBlockageCount;
|
|
|
|
int m_iteration;
|
2014-05-16 11:37:31 +00:00
|
|
|
int m_iterationLimit;
|
|
|
|
int m_itemMask;
|
2013-09-26 21:53:54 +00:00
|
|
|
bool m_forceSingleDirection, m_forceLongerPath;
|
|
|
|
bool m_cursorApproachMode;
|
|
|
|
VECTOR2I m_cursorPos;
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE::OPT_OBSTACLE m_currentObstacle[2];
|
2013-09-26 21:53:54 +00:00
|
|
|
bool m_recursiveCollision[2];
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_LOGGER m_logger;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
#endif // __PNS_WALKAROUND_H
|