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
|
|
|
*/
|
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>
|
|
|
|
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
|
|
|
|
#include <geometry/shape_line_chain.h>
|
2014-01-30 10:32:08 +00:00
|
|
|
#include <class_undoredo_container.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
class BOARD;
|
|
|
|
class BOARD_ITEM;
|
|
|
|
class D_PAD;
|
|
|
|
class TRACK;
|
2014-04-25 06:00:04 +00:00
|
|
|
class VIA;
|
2015-11-03 16:19:42 +00:00
|
|
|
class GRID_HELPER;
|
2013-09-18 17:55:16 +00:00
|
|
|
class PNS_NODE;
|
2015-02-18 00:29:54 +00:00
|
|
|
class PNS_DIFF_PAIR_PLACER;
|
|
|
|
class PNS_PLACEMENT_ALGO;
|
2013-09-18 17:55:16 +00:00
|
|
|
class PNS_LINE_PLACER;
|
|
|
|
class PNS_ITEM;
|
|
|
|
class PNS_LINE;
|
|
|
|
class PNS_SOLID;
|
|
|
|
class PNS_SEGMENT;
|
|
|
|
class PNS_JOINT;
|
|
|
|
class PNS_VIA;
|
|
|
|
class PNS_CLEARANCE_FUNC;
|
2014-05-14 13:53:54 +00:00
|
|
|
class PNS_SHOVE;
|
|
|
|
class PNS_DRAGGER;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class VIEW;
|
|
|
|
class VIEW_GROUP;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
enum PNS_ROUTER_MODE {
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
/**
|
2013-09-18 17:55:16 +00:00
|
|
|
* Class PNS_ROUTER
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
|
|
|
* Main router class.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
class PNS_ROUTER
|
|
|
|
{
|
|
|
|
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:
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_ROUTER();
|
|
|
|
~PNS_ROUTER();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void SetMode ( PNS_ROUTER_MODE aMode );
|
|
|
|
PNS_ROUTER_MODE Mode() const { return m_mode; }
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
static PNS_ROUTER* GetInstance();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void ClearWorld();
|
|
|
|
void SetBoard( BOARD* aBoard );
|
|
|
|
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;
|
2014-11-14 18:15:58 +00:00
|
|
|
bool StartRouting( const VECTOR2I& aP, PNS_ITEM* aItem, int aLayer );
|
2013-09-26 21:53:54 +00:00
|
|
|
void Move( const VECTOR2I& aP, PNS_ITEM* aItem );
|
|
|
|
bool FixRoute( const VECTOR2I& aP, PNS_ITEM* aItem );
|
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
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
int GetClearance( const PNS_ITEM* aA, const PNS_ITEM* aB ) const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_NODE* GetWorld() const
|
|
|
|
{
|
|
|
|
return m_world;
|
|
|
|
}
|
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
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void DisplayItem( const PNS_ITEM* aItem, int aColor = -1, int aClearance = -1 );
|
|
|
|
void DisplayItems( const PNS_ITEMSET& aItems );
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void DisplayDebugLine( const SHAPE_LINE_CHAIN& aLine, int aType = 0, int aWidth = 0 );
|
2014-07-09 14:50:31 +00:00
|
|
|
void DisplayDebugPoint( const VECTOR2I aPos, int aType = 0 );
|
2013-09-26 21:53:54 +00:00
|
|
|
void DisplayDebugBox( const BOX2I& aBox, int aType = 0, int aWidth = 0 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
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();
|
2015-02-18 00:29:54 +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
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_CLEARANCE_FUNC* GetClearanceFunc() const
|
|
|
|
{
|
|
|
|
return m_clearanceFunc;
|
|
|
|
}
|
2014-11-14 18:15:58 +00:00
|
|
|
bool IsPlacingVia() const;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
const PNS_ITEMSET QueryHoverItems( const VECTOR2I& aP );
|
2014-05-16 11:37:31 +00:00
|
|
|
const VECTOR2I SnapToItem( PNS_ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool StartDragging( const VECTOR2I& aP, PNS_ITEM* aItem );
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
PNS_ROUTING_SETTINGS& Settings() { return m_settings; }
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void CommitRouting( PNS_NODE* aNode );
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2014-01-30 10:32:08 +00:00
|
|
|
/**
|
2014-01-31 17:05:11 +00:00
|
|
|
* Returns the last changes introduced by the router (since the last time ClearLastChanges()
|
|
|
|
* was called or a new track has been started).
|
2014-01-30 10:32:08 +00:00
|
|
|
*/
|
2014-05-14 13:53:54 +00:00
|
|
|
const PICKED_ITEMS_LIST& GetUndoBuffer() const
|
2014-01-30 10:32:08 +00:00
|
|
|
{
|
2014-01-31 17:05:11 +00:00
|
|
|
return m_undoBuffer;
|
|
|
|
}
|
2014-01-30 10:32:08 +00:00
|
|
|
|
2014-01-31 17:05:11 +00:00
|
|
|
/**
|
|
|
|
* Clears the list of recent changes, saved to be stored in the undo buffer.
|
|
|
|
*/
|
2014-05-14 13:53:54 +00:00
|
|
|
void ClearUndoBuffer()
|
2014-01-31 17:05:11 +00:00
|
|
|
{
|
|
|
|
m_undoBuffer.ClearItemsList();
|
2014-01-30 10:32:08 +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
|
|
|
*/
|
2014-11-14 18:15:58 +00:00
|
|
|
void UpdateSizes( const PNS_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.
|
|
|
|
*/
|
|
|
|
void LoadSettings( const PNS_ROUTING_SETTINGS& aSettings )
|
|
|
|
{
|
|
|
|
m_settings = aSettings;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void EnableSnapping( bool aEnable )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_snappingEnabled = aEnable;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
bool SnappingEnabled() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return m_snappingEnabled;
|
|
|
|
}
|
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
PNS_SIZES_SETTINGS& Sizes()
|
|
|
|
{
|
|
|
|
return m_sizes;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ITEM *QueryItemByParent ( const BOARD_ITEM *aItem ) const;
|
|
|
|
|
|
|
|
BOARD *GetBoard();
|
|
|
|
|
|
|
|
void SetFailureReason ( const wxString& aReason ) { m_failureReason = aReason; }
|
|
|
|
const wxString& FailureReason() const { return m_failureReason; }
|
|
|
|
|
|
|
|
PNS_PLACEMENT_ALGO *Placer() { return m_placer; }
|
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
void SetGrid( GRID_HELPER *aGridHelper )
|
2015-07-02 14:10:49 +00:00
|
|
|
{
|
2015-11-03 16:19:42 +00:00
|
|
|
m_gridHelper = aGridHelper;
|
2015-07-02 14:10:49 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
private:
|
2014-05-16 11:37:31 +00:00
|
|
|
void movePlacing( const VECTOR2I& aP, PNS_ITEM* aItem );
|
|
|
|
void moveDragging( const VECTOR2I& aP, PNS_ITEM* aItem );
|
2014-09-30 14:46:19 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void eraseView();
|
2014-05-16 11:37:31 +00:00
|
|
|
void updateView( PNS_NODE* aNode, PNS_ITEMSET& aCurrent );
|
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
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_ITEM* pickSingleItem( PNS_ITEMSET& aItems ) const;
|
|
|
|
void splitAdjacentSegments( PNS_NODE* aNode, PNS_ITEM* aSeg, const VECTOR2I& aP );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_ITEM* syncPad( D_PAD* aPad );
|
|
|
|
PNS_ITEM* syncTrack( TRACK* aTrack );
|
2014-04-25 06:00:04 +00:00
|
|
|
PNS_ITEM* syncVia( VIA* aVia );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void commitPad( PNS_SOLID* aPad );
|
|
|
|
void commitSegment( PNS_SEGMENT* aTrack );
|
|
|
|
void commitVia( PNS_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
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
void markViolations( PNS_NODE* aNode, PNS_ITEMSET& aCurrent, PNS_NODE::ITEM_VECTOR& aRemoved );
|
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
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
BOARD* m_board;
|
|
|
|
PNS_NODE* m_world;
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_NODE* m_lastNode;
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_PLACEMENT_ALGO * m_placer;
|
2014-07-09 14:25:50 +00:00
|
|
|
PNS_DRAGGER* m_dragger;
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_SHOVE* m_shove;
|
|
|
|
int m_iterLimit;
|
|
|
|
bool m_showInterSteps;
|
|
|
|
int m_snapshotIter;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
KIGFX::VIEW* m_view;
|
|
|
|
KIGFX::VIEW_GROUP* m_previewItems;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool m_snappingEnabled;
|
|
|
|
bool m_violation;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_ROUTING_SETTINGS m_settings;
|
2015-08-21 14:37:44 +00:00
|
|
|
PNS_PCBNEW_CLEARANCE_FUNC* m_clearanceFunc;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
boost::unordered_set<BOARD_CONNECTED_ITEM*> m_hiddenItems;
|
2014-01-30 10:32:08 +00:00
|
|
|
|
|
|
|
///> Stores list of modified items in the current operation
|
|
|
|
PICKED_ITEMS_LIST m_undoBuffer;
|
2014-11-14 18:15:58 +00:00
|
|
|
PNS_SIZES_SETTINGS m_sizes;
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ROUTER_MODE m_mode;
|
|
|
|
|
|
|
|
wxString m_toolStatusbarName;
|
|
|
|
wxString m_failureReason;
|
2015-07-02 14:10:49 +00:00
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
GRID_HELPER *m_gridHelper;
|
2013-09-18 17:55:16 +00:00
|
|
|
};
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
#endif
|