2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 CERN
|
2022-12-04 04:52:21 +00:00
|
|
|
* Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-18 00:29:54 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <base_units.h> // God forgive me doing this...
|
|
|
|
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_itemset.h"
|
|
|
|
#include "pns_meander.h"
|
|
|
|
#include "pns_meander_placer_base.h"
|
|
|
|
#include "pns_router.h"
|
2016-08-15 15:16:49 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const MEANDER_SETTINGS& MEANDER_SHAPE::Settings() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return m_placer->MeanderSettings();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const MEANDER_SETTINGS& MEANDERED_LINE::Settings() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return m_placer->MeanderSettings();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2021-09-28 17:19:58 +00:00
|
|
|
void MEANDERED_LINE::MeanderSegment( const SEG& aBase, bool aSide, int aBaseIndex )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
double base_len = aBase.Length();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN lc;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-11-29 00:13:51 +00:00
|
|
|
bool singleSided = Settings().m_singleSided;
|
|
|
|
bool side = aSide;
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2D dir( aBase.B - aBase.A );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_dual )
|
2015-02-18 00:29:54 +00:00
|
|
|
AddCorner( aBase.A );
|
|
|
|
|
|
|
|
bool turning = false;
|
|
|
|
bool started = false;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_last = aBase.A;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
do
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_SHAPE m( m_placer, m_width, m_dual );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-11-09 12:11:27 +00:00
|
|
|
m.SetBaselineOffset( m_baselineOffset );
|
|
|
|
m.SetBaseIndex( aBaseIndex );
|
|
|
|
|
|
|
|
double thr = (double) m.spacing();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
bool fail = false;
|
2015-02-18 16:53:46 +00:00
|
|
|
double remaining = base_len - ( m_last - aBase.A ).EuclideanNorm();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-09-28 17:30:27 +00:00
|
|
|
auto addSingleIfFits = [&]()
|
2022-11-29 00:13:51 +00:00
|
|
|
{
|
|
|
|
fail = true;
|
|
|
|
|
|
|
|
if( m.Fit( MT_SINGLE, aBase, m_last, side ) )
|
|
|
|
{
|
|
|
|
AddMeander( new MEANDER_SHAPE( m ) );
|
|
|
|
fail = false;
|
|
|
|
started = false;
|
|
|
|
}
|
|
|
|
|
2022-12-01 15:37:05 +00:00
|
|
|
if( fail && !singleSided )
|
2022-11-29 00:13:51 +00:00
|
|
|
{
|
|
|
|
if( m.Fit( MT_SINGLE, aBase, m_last, !side ) )
|
|
|
|
{
|
|
|
|
AddMeander( new MEANDER_SHAPE( m ) );
|
|
|
|
fail = false;
|
|
|
|
started = false;
|
|
|
|
side = !side;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-09-28 17:30:27 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( remaining < Settings( ).m_step )
|
|
|
|
break;
|
|
|
|
|
2022-11-29 00:13:51 +00:00
|
|
|
if( !singleSided && remaining > 3.0 * thr )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( !turning )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < 2; i++ )
|
|
|
|
{
|
2021-09-28 17:19:58 +00:00
|
|
|
bool checkSide = ( i == 0 ) ? side : !side;
|
|
|
|
|
|
|
|
if( m.Fit( MT_CHECK_START, aBase, m_last, checkSide ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
turning = true;
|
2016-08-29 17:31:13 +00:00
|
|
|
AddMeander( new MEANDER_SHAPE( m ) );
|
2021-09-28 17:19:58 +00:00
|
|
|
side = !checkSide;
|
2015-02-18 00:29:54 +00:00
|
|
|
started = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !turning )
|
2021-09-28 17:30:27 +00:00
|
|
|
addSingleIfFits();
|
2021-07-26 23:47:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 12:11:27 +00:00
|
|
|
bool rv = m.Fit( MT_CHECK_FINISH, aBase, m_last, side );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( rv )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-11-09 12:11:27 +00:00
|
|
|
m.Fit( MT_TURN, aBase, m_last, side );
|
2016-08-29 17:31:13 +00:00
|
|
|
AddMeander( new MEANDER_SHAPE( m ) );
|
2022-12-04 04:52:21 +00:00
|
|
|
side = !side;
|
2015-02-18 00:29:54 +00:00
|
|
|
started = true;
|
2021-07-26 23:47:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 12:11:27 +00:00
|
|
|
m.Fit( MT_FINISH, aBase, m_last, side );
|
2015-02-18 00:29:54 +00:00
|
|
|
started = false;
|
2016-08-29 17:31:13 +00:00
|
|
|
AddMeander( new MEANDER_SHAPE( m ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
turning = false;
|
|
|
|
}
|
|
|
|
}
|
2021-07-26 23:47:26 +00:00
|
|
|
}
|
2022-11-29 00:13:51 +00:00
|
|
|
else if( !singleSided && started )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-11-09 12:11:27 +00:00
|
|
|
bool rv = m.Fit( MT_FINISH, aBase, m_last, side );
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( rv )
|
2016-08-29 17:31:13 +00:00
|
|
|
AddMeander( new MEANDER_SHAPE( m ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
}
|
2021-09-28 17:30:27 +00:00
|
|
|
else if( !turning && remaining > thr * 2.0 )
|
|
|
|
{
|
|
|
|
addSingleIfFits();
|
|
|
|
}
|
2021-07-26 23:47:26 +00:00
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
fail = true;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
remaining = base_len - ( m_last - aBase.A ).EuclideanNorm( );
|
|
|
|
|
|
|
|
if( remaining < Settings( ).m_step )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( fail )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_SHAPE tmp( m_placer, m_width, m_dual );
|
2015-02-18 00:29:54 +00:00
|
|
|
tmp.SetBaselineOffset( m_baselineOffset );
|
|
|
|
tmp.SetBaseIndex( aBaseIndex );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
int nextP = tmp.spacing() - 2 * tmp.cornerRadius() + Settings().m_step;
|
|
|
|
VECTOR2I pn = m_last + dir.Resize( nextP );
|
|
|
|
|
|
|
|
if( aBase.Contains( pn ) && !m_dual )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
AddCorner( pn );
|
2015-02-18 00:29:54 +00:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} while( true );
|
|
|
|
|
|
|
|
if( !m_dual )
|
|
|
|
AddCorner( aBase.B );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
int MEANDER_SHAPE::MinAmplitude() const
|
|
|
|
{
|
|
|
|
int minAmplitude = Settings().m_minAmplitude;
|
|
|
|
|
|
|
|
// DP meanders don't really support smaller amplitudes
|
|
|
|
minAmplitude = std::max( minAmplitude, std::abs( m_baselineOffset ) * 2 );
|
|
|
|
|
|
|
|
// The path length won't be correct with very small arcs
|
|
|
|
if( m_placer->MeanderSettings().m_cornerStyle == MEANDER_STYLE_ROUND )
|
|
|
|
minAmplitude = std::max( minAmplitude, m_width + std::abs( m_baselineOffset ) * 2 );
|
|
|
|
|
|
|
|
return minAmplitude;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int MEANDER_SHAPE::cornerRadius() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2018-05-20 13:08:06 +00:00
|
|
|
// TODO: fix diff-pair meandering so we can use non-100% radii
|
2018-05-21 12:48:48 +00:00
|
|
|
int rPercent = m_dual ? 100 : Settings().m_cornerRadiusPercentage;
|
2018-05-20 13:08:06 +00:00
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
int optCr = (int64_t) spacing() * rPercent / 200;
|
|
|
|
int minCr = std::abs( m_baselineOffset );
|
|
|
|
int maxCr = std::min( m_amplitude / 2, spacing() / 2 );
|
|
|
|
|
|
|
|
int cr = std::clamp( optCr, minCr, maxCr );
|
|
|
|
|
|
|
|
return cr;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int MEANDER_SHAPE::spacing( ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
if( !m_dual )
|
2021-06-19 20:04:58 +00:00
|
|
|
{
|
|
|
|
return std::max( m_width + m_placer->Clearance(), Settings().m_spacing );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
else
|
|
|
|
{
|
2021-06-19 20:04:58 +00:00
|
|
|
int sp = m_width + m_placer->Clearance() + ( 2 * std::abs( m_baselineOffset ) );
|
2016-08-15 15:16:53 +00:00
|
|
|
return std::max( sp, Settings().m_spacing );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
SHAPE_LINE_CHAIN MEANDER_SHAPE::makeMiterShape( const VECTOR2D& aP, const VECTOR2D& aDir,
|
|
|
|
bool aSide )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN lc;
|
|
|
|
|
|
|
|
if( aDir.EuclideanNorm( ) == 0.0f )
|
|
|
|
{
|
|
|
|
lc.Append( aP );
|
|
|
|
return lc;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2D dir_u( aDir );
|
|
|
|
VECTOR2D dir_v( aDir.Perpendicular( ) );
|
2016-08-15 15:16:49 +00:00
|
|
|
VECTOR2D p = aP;
|
|
|
|
lc.Append( ( int ) p.x, ( int ) p.y );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
// fixme: refactor
|
2016-08-15 15:16:53 +00:00
|
|
|
switch( m_placer->MeanderSettings().m_cornerStyle )
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
|
|
|
case MEANDER_STYLE_ROUND:
|
|
|
|
{
|
2020-10-28 13:57:55 +00:00
|
|
|
VECTOR2D center = aP + dir_v * ( aSide ? -1.0 : 1.0 );
|
2015-08-21 14:37:44 +00:00
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
lc.Append( SHAPE_ARC( center, aP, ( aSide ? -ANGLE_90 : ANGLE_90 ) ) );
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
2020-11-24 22:16:41 +00:00
|
|
|
break;
|
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
case MEANDER_STYLE_CHAMFER:
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-15 15:16:49 +00:00
|
|
|
double radius = (double) aDir.EuclideanNorm();
|
|
|
|
double correction = 0;
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
if( m_dual && radius > m_meanCornerRadius )
|
2020-11-24 22:16:41 +00:00
|
|
|
correction = (double)( -2 * abs(m_baselineOffset) ) * tan( 22.5 * M_PI / 180.0 );
|
2016-08-15 15:16:49 +00:00
|
|
|
|
|
|
|
VECTOR2D dir_cu = dir_u.Resize( correction );
|
|
|
|
VECTOR2D dir_cv = dir_v.Resize( correction );
|
|
|
|
|
|
|
|
p = aP - dir_cu;
|
2015-02-18 00:29:54 +00:00
|
|
|
lc.Append( ( int ) p.x, ( int ) p.y );
|
2016-08-15 15:16:49 +00:00
|
|
|
p = aP + dir_u + (dir_v + dir_cv) * ( aSide ? -1.0 : 1.0 );
|
|
|
|
lc.Append( ( int ) p.x, ( int ) p.y );
|
|
|
|
}
|
2020-11-24 22:16:41 +00:00
|
|
|
break;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-08-21 14:37:44 +00:00
|
|
|
p = aP + dir_u + dir_v * ( aSide ? -1.0 : 1.0 );
|
|
|
|
lc.Append( ( int ) p.x, ( int ) p.y );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return lc;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_currentTarget = aTarget;
|
2015-02-18 16:53:46 +00:00
|
|
|
m_currentTarget->Clear();
|
2015-02-18 00:29:54 +00:00
|
|
|
m_currentTarget->Append( aWhere );
|
|
|
|
m_currentDir = aDir;
|
|
|
|
m_currentPos = aWhere;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::forward( int aLength )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_currentPos += m_currentDir.Resize( aLength );
|
|
|
|
m_currentTarget->Append( m_currentPos );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-01-20 21:26:04 +00:00
|
|
|
void MEANDER_SHAPE::turn( const EDA_ANGLE& aAngle )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-01-20 21:26:04 +00:00
|
|
|
RotatePoint( m_currentDir, aAngle );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::miter( int aRadius, bool aSide )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( aRadius <= 0 )
|
|
|
|
{
|
2022-01-20 21:26:04 +00:00
|
|
|
turn( aSide ? ANGLE_90 : -ANGLE_90 );
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2D dir = m_currentDir.Resize( (double) aRadius );
|
2016-08-15 15:16:49 +00:00
|
|
|
SHAPE_LINE_CHAIN lc = makeMiterShape( m_currentPos, dir, aSide );
|
|
|
|
|
|
|
|
m_currentPos = lc.CPoint( -1 );
|
2022-01-20 21:26:04 +00:00
|
|
|
turn( aSide ? ANGLE_90 : -ANGLE_90 );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
m_currentTarget->Append( lc );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::uShape( int aSides, int aCorner, int aTop )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
forward( aSides );
|
2016-08-15 15:16:49 +00:00
|
|
|
miter( aCorner, true );
|
2015-02-18 00:29:54 +00:00
|
|
|
forward( aTop );
|
2016-08-15 15:16:49 +00:00
|
|
|
miter( aCorner, true );
|
2015-02-18 00:29:54 +00:00
|
|
|
forward( aSides );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
SHAPE_LINE_CHAIN MEANDER_SHAPE::genMeanderShape( const VECTOR2D& aP, const VECTOR2D& aDir,
|
2022-12-04 04:52:21 +00:00
|
|
|
bool aSide, MEANDER_TYPE aType,
|
2021-07-26 23:47:26 +00:00
|
|
|
int aBaselineOffset )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int cr = cornerRadius();
|
|
|
|
int offset = aBaselineOffset;
|
|
|
|
int spc = spacing();
|
2022-12-04 04:52:21 +00:00
|
|
|
int amplitude = m_amplitude;
|
|
|
|
int targetBaseLen = m_targetBaseLen;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( aSide )
|
2015-02-18 00:29:54 +00:00
|
|
|
offset *= -1;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2D dir_u_b( aDir.Resize( offset ) );
|
|
|
|
VECTOR2D dir_v_b( dir_u_b.Perpendicular() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
if( 2 * cr > amplitude )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
cr = amplitude / 2;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( 2 * cr > spc )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
cr = spc / 2;
|
|
|
|
}
|
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
if( cr - offset < 0 )
|
|
|
|
{
|
|
|
|
cr = offset;
|
|
|
|
}
|
|
|
|
|
2015-08-21 14:37:44 +00:00
|
|
|
m_meanCornerRadius = cr;
|
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
int sCorner = cr - offset;
|
|
|
|
int uCorner = cr + offset;
|
|
|
|
int startSide = amplitude - 2 * cr + std::abs( offset );
|
|
|
|
int turnSide = amplitude - cr;
|
|
|
|
int top = spc - 2 * cr;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
SHAPE_LINE_CHAIN lc;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
start( &lc, aP + dir_v_b, aDir );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( aType )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case MT_EMPTY:
|
|
|
|
{
|
|
|
|
lc.Append( aP + dir_v_b + aDir );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MT_START:
|
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
if( targetBaseLen )
|
|
|
|
top = std::max( top, targetBaseLen - sCorner - uCorner * 2 + offset );
|
|
|
|
|
|
|
|
miter( sCorner, false );
|
|
|
|
uShape( startSide, uCorner, top );
|
|
|
|
forward( std::min( sCorner, uCorner ) );
|
2015-10-05 16:28:41 +00:00
|
|
|
forward( std::abs( offset ) );
|
|
|
|
break;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case MT_FINISH:
|
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
if( targetBaseLen )
|
|
|
|
top = std::max( top, targetBaseLen - cr - spc );
|
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
start( &lc, aP - dir_u_b, aDir );
|
2022-01-20 21:26:04 +00:00
|
|
|
turn( -ANGLE_90 );
|
2022-12-04 04:52:21 +00:00
|
|
|
forward( std::min( sCorner, uCorner ) );
|
2015-10-05 16:28:41 +00:00
|
|
|
forward( std::abs( offset ) );
|
2022-12-04 04:52:21 +00:00
|
|
|
uShape( startSide, uCorner, top );
|
|
|
|
miter( sCorner, false );
|
|
|
|
|
|
|
|
if( targetBaseLen >= spc + cr )
|
|
|
|
lc.Append( aP + dir_v_b + aDir.Resize( targetBaseLen ) );
|
|
|
|
else
|
|
|
|
lc.Append( aP + dir_v_b + aDir.Resize( 2 * spc - cr ) );
|
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case MT_TURN:
|
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
if( targetBaseLen )
|
|
|
|
top = std::max( top, targetBaseLen - uCorner * 2 + offset * 2 );
|
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
start( &lc, aP - dir_u_b, aDir );
|
2022-01-20 21:26:04 +00:00
|
|
|
turn( -ANGLE_90 );
|
2015-10-05 16:28:41 +00:00
|
|
|
forward( std::abs( offset ) );
|
2022-12-04 04:52:21 +00:00
|
|
|
uShape( turnSide, uCorner, top );
|
2015-10-05 16:28:41 +00:00
|
|
|
forward( std::abs( offset ) );
|
|
|
|
break;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case MT_SINGLE:
|
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
if( targetBaseLen )
|
|
|
|
top = std::max( top, ( targetBaseLen - sCorner * 2 - uCorner * 2 ) / 2 );
|
|
|
|
|
|
|
|
miter( sCorner, false );
|
|
|
|
uShape( startSide, uCorner, top );
|
|
|
|
miter( sCorner, false );
|
2021-06-19 19:50:45 +00:00
|
|
|
lc.Append( aP + dir_v_b + aDir.Resize( 2 * spc ) );
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
default: break;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aSide )
|
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
SEG axis( aP, aP + aDir );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-04-11 12:28:32 +00:00
|
|
|
lc.Mirror( axis );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lc;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool MEANDERED_LINE::CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int i = m_meanders.size() - 1; i >= 0; i-- )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_SHAPE* m = m_meanders[i];
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m->Type() == MT_EMPTY || m->Type() == MT_CORNER )
|
2015-02-18 00:29:54 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const SEG& b1 = aShape->BaseSegment();
|
|
|
|
const SEG& b2 = m->BaseSegment();
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( b1.ApproxParallel( b2 ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
continue;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
int n = m->CLine( 0 ).SegmentCount();
|
|
|
|
|
|
|
|
for( int j = n - 1; j >= 0; j-- )
|
2021-07-26 23:47:26 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
if( aShape->CLine( 0 ).Collide( m->CLine( 0 ) .CSegment( j ), aClearance ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2021-07-26 23:47:26 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool MEANDER_SHAPE::Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const MEANDER_SETTINGS& st = Settings();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
bool checkMode = false;
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_TYPE prim1, prim2;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aType == MT_CHECK_START )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
prim1 = MT_START;
|
|
|
|
prim2 = MT_TURN;
|
|
|
|
checkMode = true;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( aType == MT_CHECK_FINISH )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
prim1 = MT_TURN;
|
|
|
|
prim2 = MT_FINISH;
|
|
|
|
checkMode = true;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( checkMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_SHAPE m1( m_placer, m_width, m_dual );
|
|
|
|
MEANDER_SHAPE m2( m_placer, m_width, m_dual );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m1.SetBaselineOffset( m_baselineOffset );
|
|
|
|
m2.SetBaselineOffset( m_baselineOffset );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool c1 = m1.Fit( prim1, aSeg, aP, aSide );
|
2015-02-18 00:29:54 +00:00
|
|
|
bool c2 = false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( c1 )
|
|
|
|
c2 = m2.Fit( prim2, aSeg, m1.End(), !aSide );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( c1 && c2 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_type = prim1;
|
|
|
|
m_shapes[0] = m1.m_shapes[0];
|
|
|
|
m_shapes[1] = m1.m_shapes[1];
|
|
|
|
m_baseSeg =aSeg;
|
|
|
|
m_p0 = aP;
|
|
|
|
m_side = aSide;
|
|
|
|
m_amplitude = m1.Amplitude();
|
|
|
|
m_dual = m1.m_dual;
|
|
|
|
m_baseSeg = m1.m_baseSeg;
|
|
|
|
m_baseIndex = m1.m_baseIndex;
|
2015-02-18 16:53:46 +00:00
|
|
|
updateBaseSegment();
|
2015-02-18 00:29:54 +00:00
|
|
|
m_baselineOffset = m1.m_baselineOffset;
|
|
|
|
return true;
|
2021-07-26 23:47:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2021-07-26 23:47:26 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
int minAmpl = MinAmplitude();
|
|
|
|
int maxAmpl = std::max( st.m_maxAmplitude, minAmpl );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
for( int ampl = maxAmpl; ampl >= minAmpl; ampl -= st.m_step )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
m_amplitude = ampl;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_dual )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, m_baselineOffset );
|
|
|
|
m_shapes[1] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, -m_baselineOffset );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
m_shapes[0] = genMeanderShape( aP, aSeg.B - aSeg.A, aSide, aType, 0 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_type = aType;
|
2015-02-18 16:53:46 +00:00
|
|
|
m_baseSeg = aSeg;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_p0 = aP;
|
|
|
|
m_side = aSide;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
updateBaseSegment();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( m_placer->CheckFit( this ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::Recalculate()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-12-04 04:52:21 +00:00
|
|
|
m_shapes[0] = genMeanderShape( m_p0, m_baseSeg.B - m_baseSeg.A, m_side, m_type,
|
2021-07-26 23:47:26 +00:00
|
|
|
m_dual ? m_baselineOffset : 0 );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( m_dual )
|
2021-07-26 23:47:26 +00:00
|
|
|
m_shapes[1] = genMeanderShape( m_p0, m_baseSeg.B - m_baseSeg.A, m_side, m_type,
|
2022-12-04 04:52:21 +00:00
|
|
|
-m_baselineOffset );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
updateBaseSegment();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::Resize( int aAmpl )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aAmpl < 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_amplitude = aAmpl;
|
|
|
|
|
|
|
|
Recalculate();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::MakeEmpty()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
updateBaseSegment();
|
|
|
|
|
|
|
|
VECTOR2I dir = m_clippedBaseSeg.B - m_clippedBaseSeg.A;
|
|
|
|
|
|
|
|
m_type = MT_EMPTY;
|
2022-12-04 04:52:21 +00:00
|
|
|
m_amplitude = 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
m_shapes[0] = genMeanderShape( m_p0, dir, m_side, m_type, m_dual ? m_baselineOffset : 0 );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_dual )
|
2022-12-04 04:52:21 +00:00
|
|
|
m_shapes[1] = genMeanderShape( m_p0, dir, m_side, m_type, -m_baselineOffset );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDERED_LINE::AddCorner( const VECTOR2I& aA, const VECTOR2I& aB )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_SHAPE* m = new MEANDER_SHAPE( m_placer, m_width, m_dual );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m->MakeCorner( aA, aB );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_last = aA;
|
|
|
|
|
|
|
|
m_meanders.push_back( m );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
|
2021-08-09 20:00:35 +00:00
|
|
|
void MEANDERED_LINE::AddArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 )
|
|
|
|
{
|
|
|
|
MEANDER_SHAPE* m = new MEANDER_SHAPE( m_placer, m_width, m_dual );
|
|
|
|
|
|
|
|
m->MakeArc( aArc1, aArc2 );
|
|
|
|
m_last = aArc1.GetP1();
|
|
|
|
|
|
|
|
m_meanders.push_back( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MEANDERED_LINE::AddArcAndPt( const SHAPE_ARC& aArc1, const VECTOR2I& aPt2 )
|
|
|
|
{
|
|
|
|
SHAPE_ARC arc2( aPt2, aPt2, aPt2, 0 );
|
|
|
|
|
|
|
|
AddArc( aArc1, arc2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MEANDERED_LINE::AddPtAndArc( const VECTOR2I& aPt1, const SHAPE_ARC& aArc2 )
|
|
|
|
{
|
|
|
|
SHAPE_ARC arc1( aPt1, aPt1, aPt1, 0 );
|
|
|
|
|
|
|
|
AddArc( arc1, aArc2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void MEANDER_SHAPE::MakeCorner( const VECTOR2I& aP1, const VECTOR2I& aP2 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
SetType( MT_CORNER );
|
2015-02-18 16:53:46 +00:00
|
|
|
m_shapes[0].Clear();
|
|
|
|
m_shapes[1].Clear();
|
|
|
|
m_shapes[0].Append( aP1 );
|
|
|
|
m_shapes[1].Append( aP2 );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_clippedBaseSeg.A = aP1;
|
|
|
|
m_clippedBaseSeg.B = aP1;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-08-09 20:00:35 +00:00
|
|
|
void MEANDER_SHAPE::MakeArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 )
|
|
|
|
{
|
|
|
|
SetType( MT_CORNER );
|
|
|
|
m_shapes[0].Clear();
|
|
|
|
m_shapes[1].Clear();
|
|
|
|
m_shapes[0].Append( aArc1 );
|
|
|
|
m_shapes[1].Append( aArc2 );
|
|
|
|
m_clippedBaseSeg.A = aArc1.GetP1();
|
|
|
|
m_clippedBaseSeg.B = aArc1.GetP1();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDERED_LINE::AddMeander( MEANDER_SHAPE* aShape )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m_last = aShape->BaseSegment().B;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_meanders.push_back( aShape );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDERED_LINE::Clear()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( MEANDER_SHAPE* m : m_meanders )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
delete m;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_meanders.clear( );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int MEANDER_SHAPE::BaselineLength() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return m_clippedBaseSeg.Length();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
long long int MEANDER_SHAPE::CurrentLength() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return CLine( 0 ).Length();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-12-04 04:52:21 +00:00
|
|
|
long long int MEANDER_SHAPE::MinTunableLength() const
|
|
|
|
{
|
|
|
|
MEANDER_SHAPE copy = *this;
|
|
|
|
|
|
|
|
copy.SetTargetBaselineLength( BaselineLength() );
|
|
|
|
copy.Resize( copy.MinAmplitude() );
|
|
|
|
|
|
|
|
return copy.CurrentLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_SHAPE::updateBaseSegment( )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( m_dual )
|
|
|
|
{
|
|
|
|
VECTOR2I midpA = ( CLine( 0 ).CPoint( 0 ) + CLine( 1 ).CPoint( 0 ) ) / 2;
|
|
|
|
VECTOR2I midpB = ( CLine( 0 ).CPoint( -1 ) + CLine( 1 ).CPoint( -1 ) ) / 2;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_clippedBaseSeg.A = m_baseSeg.LineProject( midpA );
|
|
|
|
m_clippedBaseSeg.B = m_baseSeg.LineProject( midpB );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
m_clippedBaseSeg.A = m_baseSeg.LineProject( CLine( 0 ).CPoint( 0 ) );
|
|
|
|
m_clippedBaseSeg.B = m_baseSeg.LineProject( CLine( 0 ).CPoint( -1 ) );
|
|
|
|
}
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|