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_WALKAROUND_H
|
|
|
|
#define __PNS_WALKAROUND_H
|
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
#include <set>
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#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
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class WALKAROUND : public ALGO_BASE
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
static const int DefaultIterationLimit = 50;
|
|
|
|
|
|
|
|
public:
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND( NODE* aWorld, ROUTER* aRouter ) :
|
|
|
|
ALGO_BASE ( aRouter ),
|
2014-11-14 19:19:00 +00:00
|
|
|
m_world( aWorld ),
|
2014-05-16 11:37:31 +00:00
|
|
|
m_iterationLimit( DefaultIterationLimit )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
m_forceWinding = false;
|
2016-08-29 17:31:13 +00:00
|
|
|
m_itemMask = ITEM::ANY_T;
|
2015-04-22 16:39:49 +00:00
|
|
|
|
|
|
|
// Initialize other members, to avoid uninitialized variables.
|
|
|
|
m_iteration = 0;
|
|
|
|
m_forceCw = false;
|
2022-06-03 21:18:42 +00:00
|
|
|
m_forceLongerPath = false;
|
2022-10-26 22:27:01 +00:00
|
|
|
m_lengthLimitOn = true;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
~WALKAROUND() {};
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
enum WALKAROUND_STATUS
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
IN_PROGRESS = 0,
|
2020-02-19 17:22:37 +00:00
|
|
|
ALMOST_DONE,
|
2013-09-26 21:53:54 +00:00
|
|
|
DONE,
|
|
|
|
STUCK
|
|
|
|
};
|
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
struct RESULT
|
|
|
|
{
|
|
|
|
RESULT( WALKAROUND_STATUS aStatusCw = STUCK, WALKAROUND_STATUS aStatusCcw = STUCK, const LINE& aLineCw = LINE(), const LINE& aLineCcw = LINE() )
|
|
|
|
{
|
|
|
|
statusCw = aStatusCw;
|
|
|
|
statusCcw = aStatusCcw;
|
|
|
|
lineCw = aLineCw;
|
|
|
|
lineCcw = aLineCcw;
|
|
|
|
}
|
|
|
|
|
|
|
|
WALKAROUND_STATUS statusCw, statusCcw;
|
|
|
|
LINE lineCw, lineCcw;
|
|
|
|
};
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void SetWorld( NODE* aNode )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
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 )
|
2016-08-29 17:31:13 +00:00
|
|
|
m_itemMask = ITEM::SOLID_T;
|
2014-05-14 13:53:54 +00:00
|
|
|
else
|
2016-08-29 17:31:13 +00:00
|
|
|
m_itemMask = ITEM::ANY_T;
|
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
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void SetForceWinding ( bool aEnabled, bool aCw )
|
|
|
|
{
|
|
|
|
m_forceCw = aCw;
|
|
|
|
m_forceWinding = aEnabled;
|
|
|
|
}
|
|
|
|
|
2022-06-03 21:18:42 +00:00
|
|
|
void RestrictToSet( bool aEnabled, const std::set<ITEM*>& aSet );
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND_STATUS Route( const LINE& aInitialPath, LINE& aWalkPath,
|
2013-09-26 21:53:54 +00:00
|
|
|
bool aOptimize = true );
|
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
const RESULT Route( const LINE& aInitialPath );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2022-10-26 22:27:01 +00:00
|
|
|
void SetLengthLimit( bool aEnable )
|
|
|
|
{
|
|
|
|
m_lengthLimitOn = aEnable;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
private:
|
2016-08-29 17:31:13 +00:00
|
|
|
void start( const LINE& aInitialPath );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND_STATUS singleStep( LINE& aPath, bool aWindingDirection );
|
|
|
|
NODE::OPT_OBSTACLE nearestObstacle( const LINE& aPath );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_world;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
int m_iteration;
|
2014-05-16 11:37:31 +00:00
|
|
|
int m_iterationLimit;
|
|
|
|
int m_itemMask;
|
2015-02-18 00:29:54 +00:00
|
|
|
bool m_forceWinding;
|
|
|
|
bool m_forceCw;
|
2013-09-26 21:53:54 +00:00
|
|
|
VECTOR2I m_cursorPos;
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OPT_OBSTACLE m_currentObstacle[2];
|
|
|
|
std::set<ITEM*> m_restrictedSet;
|
2022-06-03 21:18:42 +00:00
|
|
|
std::vector<VECTOR2I> m_restrictedVertices;
|
|
|
|
bool m_forceLongerPath;
|
2022-10-26 22:27:01 +00:00
|
|
|
bool m_lengthLimitOn;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
#endif // __PNS_WALKAROUND_H
|