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
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#ifndef __PNS_ROUTER_H
|
|
|
|
#define __PNS_ROUTER_H
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
2016-08-29 17:48:16 +00:00
|
|
|
#include <memory>
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <core/optional.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
|
2019-08-15 07:21:48 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
|
|
|
|
#include "pns_routing_settings.h"
|
2014-11-14 18:15:58 +00:00
|
|
|
#include "pns_sizes_settings.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_itemset.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_node.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
|
|
|
|
class VIEW;
|
|
|
|
class VIEW_GROUP;
|
|
|
|
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class DEBUG_DECORATOR;
|
|
|
|
class NODE;
|
|
|
|
class DIFF_PAIR_PLACER;
|
|
|
|
class PLACEMENT_ALGO;
|
|
|
|
class LINE_PLACER;
|
|
|
|
class ITEM;
|
|
|
|
class LINE;
|
|
|
|
class SOLID;
|
|
|
|
class SEGMENT;
|
|
|
|
class JOINT;
|
|
|
|
class VIA;
|
|
|
|
class RULE_RESOLVER;
|
|
|
|
class SHOVE;
|
|
|
|
class DRAGGER;
|
|
|
|
|
|
|
|
enum ROUTER_MODE {
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_MODE_ROUTE_SINGLE = 1,
|
|
|
|
PNS_MODE_ROUTE_DIFF_PAIR,
|
|
|
|
PNS_MODE_TUNE_SINGLE,
|
|
|
|
PNS_MODE_TUNE_DIFF_PAIR,
|
|
|
|
PNS_MODE_TUNE_DIFF_PAIR_SKEW
|
|
|
|
};
|
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
enum DRAG_MODE
|
|
|
|
{
|
|
|
|
DM_CORNER = 0x1,
|
|
|
|
DM_SEGMENT = 0x2,
|
|
|
|
DM_VIA = 0x4,
|
|
|
|
DM_FREE_ANGLE = 0x8,
|
|
|
|
DM_ANY = 0x7
|
|
|
|
};
|
2013-09-26 21:53:54 +00:00
|
|
|
/**
|
2016-08-29 17:31:13 +00:00
|
|
|
* Class ROUTER
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
|
|
|
* Main router class.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class ROUTER_IFACE
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTER_IFACE() {};
|
|
|
|
virtual ~ROUTER_IFACE() {};
|
|
|
|
|
|
|
|
virtual void SetRouter( ROUTER* aRouter ) = 0;
|
|
|
|
virtual void SyncWorld( NODE* aNode ) = 0;
|
|
|
|
virtual void AddItem( ITEM* aItem ) = 0;
|
|
|
|
virtual void RemoveItem( ITEM* aItem ) = 0;
|
2019-08-15 07:21:48 +00:00
|
|
|
virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) = 0;
|
2019-04-08 04:24:30 +00:00
|
|
|
virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0;
|
2016-08-29 17:31:13 +00:00
|
|
|
virtual void HideItem( ITEM* aItem ) = 0;
|
2016-08-15 15:16:53 +00:00
|
|
|
virtual void Commit() = 0;
|
|
|
|
// virtual void Abort () = 0;
|
|
|
|
|
|
|
|
virtual void EraseView() = 0;
|
|
|
|
virtual void UpdateNet( int aNetCode ) = 0;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
virtual RULE_RESOLVER* GetRuleResolver() = 0;
|
|
|
|
virtual DEBUG_DECORATOR* GetDebugDecorator() = 0;
|
2016-08-15 15:16:47 +00:00
|
|
|
};
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class ROUTER
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
enum RouterState
|
|
|
|
{
|
|
|
|
IDLE,
|
2014-05-14 13:53:54 +00:00
|
|
|
DRAG_SEGMENT,
|
|
|
|
ROUTE_TRACK
|
2013-09-26 21:53:54 +00:00
|
|
|
};
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
public:
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTER();
|
|
|
|
~ROUTER();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void SetInterface( ROUTER_IFACE* aIface );
|
|
|
|
void SetMode ( ROUTER_MODE aMode );
|
|
|
|
ROUTER_MODE Mode() const { return m_mode; }
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
static ROUTER* GetInstance();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void ClearWorld();
|
|
|
|
void SyncWorld();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
void SetView( KIGFX::VIEW* aView );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
bool RoutingInProgress() const;
|
2016-08-29 17:31:13 +00:00
|
|
|
bool StartRouting( const VECTOR2I& aP, ITEM* aItem, int aLayer );
|
|
|
|
void Move( const VECTOR2I& aP, ITEM* aItem );
|
2018-06-19 17:29:36 +00:00
|
|
|
bool FixRoute( const VECTOR2I& aP, ITEM* aItem, bool aForceFinish = false );
|
2017-08-03 15:53:07 +00:00
|
|
|
void BreakSegment( ITEM *aItem, const VECTOR2I& aP );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void StopRouting();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int GetClearance( const ITEM* aA, const ITEM* aB ) const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* GetWorld() const
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:48:16 +00:00
|
|
|
return m_world.get();
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void FlipPosture();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-04-08 04:24:30 +00:00
|
|
|
void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false );
|
2016-08-29 17:31:13 +00:00
|
|
|
void DisplayItems( const ITEM_SET& aItems );
|
|
|
|
void DeleteTraces( ITEM* aStartItem, bool aWholeTrack );
|
2013-09-26 21:53:54 +00:00
|
|
|
void SwitchLayer( int layer );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
void ToggleViaPlacement();
|
2016-06-21 15:06:28 +00:00
|
|
|
void SetOrthoMode( bool aEnable );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
int GetCurrentLayer() const;
|
2015-08-21 14:35:34 +00:00
|
|
|
const std::vector<int> GetCurrentNets() const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void DumpLog();
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
RULE_RESOLVER* GetRuleResolver() const
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
return m_iface->GetRuleResolver();
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
bool IsPlacingVia() const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET QueryHoverItems( const VECTOR2I& aP );
|
|
|
|
const VECTOR2I SnapToItem( ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
bool StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode = DM_ANY );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
void SetIterLimit( int aX ) { m_iterLimit = aX; }
|
|
|
|
int GetIterLimit() const { return m_iterLimit; };
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void SetShowIntermediateSteps( bool aX, int aSnapshotIter = -1 )
|
|
|
|
{
|
|
|
|
m_showInterSteps = aX;
|
|
|
|
m_snapshotIter = aSnapshotIter;
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool GetShowIntermediateSteps() const { return m_showInterSteps; }
|
|
|
|
int GetShapshotIter() const { return m_snapshotIter; }
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTING_SETTINGS& Settings() { return m_settings; }
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void CommitRouting( NODE* aNode );
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
/**
|
|
|
|
* Applies stored settings.
|
2014-05-16 11:37:31 +00:00
|
|
|
* @see Settings()
|
2014-05-14 13:53:54 +00:00
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
void UpdateSizes( const SIZES_SETTINGS& aSizes );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-14 14:53:49 +00:00
|
|
|
/**
|
|
|
|
* Changes routing settings to ones passed in the parameter.
|
|
|
|
* @param aSettings are the new settings.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
void LoadSettings( const ROUTING_SETTINGS& aSettings )
|
2014-05-14 14:53:49 +00:00
|
|
|
{
|
|
|
|
m_settings = aSettings;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SIZES_SETTINGS& Sizes()
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
return m_sizes;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* QueryItemByParent( const BOARD_ITEM* aItem ) const;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
void SetFailureReason( const wxString& aReason ) { m_failureReason = aReason; }
|
2015-02-18 00:29:54 +00:00
|
|
|
const wxString& FailureReason() const { return m_failureReason; }
|
|
|
|
|
2016-08-29 17:48:16 +00:00
|
|
|
PLACEMENT_ALGO* Placer() { return m_placer.get(); }
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTER_IFACE* GetInterface() const
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
return m_iface;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
private:
|
2016-08-29 17:31:13 +00:00
|
|
|
void movePlacing( const VECTOR2I& aP, ITEM* aItem );
|
|
|
|
void moveDragging( const VECTOR2I& aP, ITEM* aItem );
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void eraseView();
|
2019-04-08 04:24:30 +00:00
|
|
|
void updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging = false );
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void clearViewFlags();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
// optHoverItem queryHoverItemEx(const VECTOR2I& aP);
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* pickSingleItem( ITEM_SET& aItems ) const;
|
|
|
|
void splitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* syncPad( D_PAD* aPad );
|
|
|
|
ITEM* syncTrack( TRACK* aTrack );
|
|
|
|
ITEM* syncVia( VIA* aVia );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void commitPad( SOLID* aPad );
|
|
|
|
void commitSegment( SEGMENT* aTrack );
|
|
|
|
void commitVia( VIA* aVia );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void highlightCurrent( bool enabled );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved );
|
2018-02-03 09:39:46 +00:00
|
|
|
bool isStartingPointRoutable( const VECTOR2I& aWhere, int aLayer );
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
VECTOR2I m_currentEnd;
|
2013-09-26 21:53:54 +00:00
|
|
|
RouterState m_state;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:48:16 +00:00
|
|
|
std::unique_ptr< NODE > m_world;
|
|
|
|
NODE* m_lastNode;
|
|
|
|
|
|
|
|
std::unique_ptr< PLACEMENT_ALGO > m_placer;
|
|
|
|
std::unique_ptr< DRAGGER > m_dragger;
|
|
|
|
std::unique_ptr< SHOVE > m_shove;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTER_IFACE* m_iface;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int m_iterLimit;
|
|
|
|
bool m_showInterSteps;
|
|
|
|
int m_snapshotIter;
|
|
|
|
bool m_violation;
|
2017-08-03 15:53:07 +00:00
|
|
|
bool m_forceMarkObstaclesMode = false;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTING_SETTINGS m_settings;
|
|
|
|
SIZES_SETTINGS m_sizes;
|
|
|
|
ROUTER_MODE m_mode;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
wxString m_toolStatusbarName;
|
|
|
|
wxString m_failureReason;
|
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
|