2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 CERN
|
2023-08-22 12:06:33 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2015-02-18 00:29:54 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PNS_DIFF_PLACER_H
|
|
|
|
#define __PNS_DIFF_PLACER_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
#include "pns_sizes_settings.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_algo_base.h"
|
|
|
|
#include "pns_diff_pair.h"
|
|
|
|
|
|
|
|
#include "pns_placement_algo.h"
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class ROUTER;
|
|
|
|
class SHOVE;
|
|
|
|
class OPTIMIZER;
|
|
|
|
class VIA;
|
|
|
|
class SIZES_SETTINGS;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Single track placement algorithm.
|
2015-02-18 00:29:54 +00:00
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* Interactively routes a track and applies shove and walk around algorithms when needed.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class DIFF_PAIR_PLACER : public PLACEMENT_ALGO
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-08-29 17:31:13 +00:00
|
|
|
DIFF_PAIR_PLACER( ROUTER* aRouter );
|
|
|
|
~DIFF_PAIR_PLACER();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
static bool FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, ITEM* aItem,
|
|
|
|
DP_PRIMITIVE_PAIR& aPair, wxString* aErrorMsg = nullptr );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Start routing a single track at point aP, taking item aStartItem as anchor (unless NULL).
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
bool Start( const VECTOR2I& aP, ITEM* aStartItem ) override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Move the end of the currently routed trace to the point \a aP, taking \a aEndItem as
|
|
|
|
* anchor (if not NULL).
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Commit the currently routed track to the parent node, taking \a aP as the final end
|
|
|
|
* point and \a aEndItem as the final anchor (if provided).
|
2015-02-18 00:29:54 +00:00
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* @return true if route has been committed. May return false if the routing result is
|
|
|
|
* violating design rules. In such cases, the track is only committed if
|
|
|
|
* #Settings.CanViolateDRC() is on.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2018-06-19 17:29:36 +00:00
|
|
|
bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2020-03-06 17:55:20 +00:00
|
|
|
/// @copydoc PLACEMENT_ALGO::CommitPlacement()
|
2020-03-04 23:21:50 +00:00
|
|
|
bool CommitPlacement() override;
|
|
|
|
|
2020-03-06 17:55:20 +00:00
|
|
|
/// @copydoc PLACEMENT_ALGO::AbortPlacement()
|
2020-03-04 23:21:50 +00:00
|
|
|
bool AbortPlacement() override;
|
|
|
|
|
2020-03-06 17:55:20 +00:00
|
|
|
/// @copydoc PLACEMENT_ALGO::HasPlacedAnything()
|
2020-03-04 23:21:50 +00:00
|
|
|
bool HasPlacedAnything() const override;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Enable/disable a via at the end of currently routed trace.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
bool ToggleVia( bool aEnabled ) override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Set the current routing layer.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
bool SetLayer( int aLayer ) override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the complete routed line, as a single-member ITEM_SET.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
const ITEM_SET Traces() override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-09-12 19:43:36 +00:00
|
|
|
/**
|
|
|
|
* Return the current start of the line being placed.
|
|
|
|
*/
|
|
|
|
const VECTOR2I& CurrentStart() const override
|
|
|
|
{
|
|
|
|
return m_currentStart;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the current end of the line being placed. It may not be equal to the cursor
|
|
|
|
* position due to collisions.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-25 17:06:49 +00:00
|
|
|
const VECTOR2I& CurrentEnd() const override
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_currentEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-08-22 12:06:33 +00:00
|
|
|
* Return the net of currently routed track.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2023-08-22 12:06:33 +00:00
|
|
|
const std::vector<NET_HANDLE> CurrentNets() const override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the layer of currently routed track.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-25 17:06:49 +00:00
|
|
|
int CurrentLayer() const override
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_currentLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the most recent world state.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
NODE* CurrentNode( bool aLoopsRemoved = false ) const override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Toggle the current posture (straight/diagonal) of the trace head.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
void FlipPosture() override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Perform on-the-fly update of the width, via diameter & drill size from a settings class.
|
2015-02-18 00:29:54 +00:00
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* Used to dynamically change these parameters as the track is routed.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
void UpdateSizes( const SIZES_SETTINGS& aSizes ) override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
bool IsPlacingVia() const override { return m_placingVia; }
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
void SetOrthoMode( bool aOrthoMode ) override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
void GetModifiedNets( std::vector<NET_HANDLE>& aNets ) const override;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
private:
|
2015-02-18 00:29:54 +00:00
|
|
|
int viaGap() const;
|
|
|
|
int gap() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Re-route the current track to point \a aP.
|
2015-02-18 00:29:54 +00:00
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* Returns true, when routing has completed successfully (i.e. the trace end has reached
|
|
|
|
* point aP), and false if the trace was stuck somewhere on the way. May call routeStep()
|
2015-02-18 00:29:54 +00:00
|
|
|
* repetitively due to mouse smoothing.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
|
|
|
* @param aP is the ending point of current route.
|
|
|
|
* @return true if the routing is complete.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
|
|
|
bool route( const VECTOR2I& aP );
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Draw the "leading" ratsnest line, which connects the end of currently routed track and
|
|
|
|
* the nearest yet unrouted item. If the routing for current net is complete, draws nothing.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
|
|
|
void updateLeadingRatLine();
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Set the board to route.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
void setWorld( NODE* aWorld );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Initialize placement of a new line with given parameters.
|
2015-02-18 00:29:54 +00:00
|
|
|
*/
|
2016-08-15 15:16:51 +00:00
|
|
|
void initPlacement( );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Set preferred direction of the very first track segment to be laid.
|
2015-02-18 00:29:54 +00:00
|
|
|
*
|
|
|
|
* Used by posture switching mechanism.
|
|
|
|
*/
|
|
|
|
void setInitialDirection( const DIRECTION_45& aDirection );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
bool routeHead( const VECTOR2I& aP );
|
2016-08-29 17:31:13 +00:00
|
|
|
bool tryWalkDp( NODE* aNode, DIFF_PAIR& aPair, bool aSolidsOnly );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< route step, walk around mode
|
2015-02-18 00:29:54 +00:00
|
|
|
bool rhWalkOnly( const VECTOR2I& aP );
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< route step, shove mode
|
2015-02-18 00:29:54 +00:00
|
|
|
bool rhShoveOnly ( const VECTOR2I& aP );
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< route step, mark obstacles mode
|
2015-02-18 00:29:54 +00:00
|
|
|
bool rhMarkObstacles( const VECTOR2I& aP );
|
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
const VIA makeVia ( const VECTOR2I& aP, NET_HANDLE aNet );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
bool attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent, DIFF_PAIR& aWalk, bool aPFirst,
|
|
|
|
bool aWindCw, bool aSolidsOnly );
|
2015-02-18 00:29:54 +00:00
|
|
|
bool propagateDpHeadForces ( const VECTOR2I& aP, VECTOR2I& aNewP );
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
RT_START = 0,
|
|
|
|
RT_ROUTE = 1,
|
|
|
|
RT_FINISH = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
State m_state;
|
|
|
|
|
|
|
|
bool m_chainedPlacement;
|
|
|
|
bool m_initialDiagonal;
|
|
|
|
bool m_startDiagonal;
|
|
|
|
bool m_fitOk;
|
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
NET_HANDLE m_netP, m_netN;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR m_start;
|
2022-08-25 22:50:47 +00:00
|
|
|
std::optional<DP_PRIMITIVE_PAIR> m_prevPair;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< current algorithm iteration
|
2015-02-18 00:29:54 +00:00
|
|
|
int m_iteration;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< pointer to world to search colliding items
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_world;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< current routing start point (end of tail, beginning of head)
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2I m_p_start;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< The shove engine
|
2021-10-12 16:53:52 +00:00
|
|
|
std::unique_ptr<SHOVE> m_shove;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Current world state
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_currentNode;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Postprocessed world state (including marked collisions & removed loops)
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* m_lastNode;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SIZES_SETTINGS m_sizes;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Are we placing a via?
|
2015-02-18 00:29:54 +00:00
|
|
|
bool m_placingVia;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< current via diameter
|
2015-02-18 00:29:54 +00:00
|
|
|
int m_viaDiameter;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< current via drill
|
2015-02-18 00:29:54 +00:00
|
|
|
int m_viaDrill;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< current track width
|
2015-02-18 00:29:54 +00:00
|
|
|
int m_currentWidth;
|
|
|
|
|
|
|
|
int m_currentLayer;
|
|
|
|
|
|
|
|
bool m_startsOnVia;
|
|
|
|
bool m_orthoMode;
|
|
|
|
bool m_snapOnTarget;
|
|
|
|
|
|
|
|
VECTOR2I m_currentEnd, m_currentStart;
|
2016-08-29 17:31:13 +00:00
|
|
|
DIFF_PAIR m_currentTrace;
|
2021-04-15 02:43:54 +00:00
|
|
|
bool m_currentTraceOk;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* m_currentEndItem;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
bool m_idle;
|
|
|
|
};
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
#endif // __PNS_LINE_PLACER_H
|