2023-10-07 03:54:14 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 Alex Shvartzkop <dudesuchamazing@gmail.com>
|
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pcb_generator.h>
|
|
|
|
#include <generators_mgr.h>
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <magic_enum.hpp>
|
|
|
|
|
|
|
|
#include <wx/debug.h>
|
2023-12-02 10:32:45 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
#include <geometry/shape_circle.h>
|
2023-10-09 14:22:16 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2023-10-09 20:55:07 +00:00
|
|
|
#include <dialogs/dialog_unit_entry.h>
|
2023-10-09 14:22:16 +00:00
|
|
|
#include <collectors.h>
|
2023-10-11 15:02:07 +00:00
|
|
|
#include <scoped_set_reset.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-09 20:55:07 +00:00
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <drc/drc_engine.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
#include <pcb_track.h>
|
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_group.h>
|
|
|
|
|
|
|
|
#include <tool/edit_points.h>
|
|
|
|
#include <tools/drawing_tool.h>
|
|
|
|
#include <tools/generator_tool.h>
|
2023-10-09 14:22:16 +00:00
|
|
|
#include <tools/pcb_picker_tool.h>
|
|
|
|
#include <tools/pcb_selection_tool.h>
|
2023-10-11 13:43:54 +00:00
|
|
|
#include <tools/zone_filler_tool.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
#include <preview_items/draw_context.h>
|
2023-12-02 10:32:45 +00:00
|
|
|
#include <preview_items/preview_utils.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
#include <router/pns_dp_meander_placer.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
#include <router/pns_meander_placer_base.h>
|
|
|
|
#include <router/pns_meander.h>
|
|
|
|
#include <router/pns_kicad_iface.h>
|
|
|
|
#include <router/pns_segment.h>
|
|
|
|
#include <router/pns_arc.h>
|
2023-11-28 17:55:37 +00:00
|
|
|
#include <router/pns_solid.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
#include <router/pns_topology.h>
|
2023-12-02 10:32:45 +00:00
|
|
|
#include <router/router_preview_item.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
#include <dialogs/dialog_tuning_pattern_properties.h>
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum LENGTH_TUNING_MODE
|
|
|
|
{
|
|
|
|
SINGLE,
|
|
|
|
DIFF_PAIR,
|
|
|
|
DIFF_PAIR_SKEW
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
class TUNING_STATUS_VIEW_ITEM : public EDA_ITEM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TUNING_STATUS_VIEW_ITEM( PCB_BASE_EDIT_FRAME* aFrame ) :
|
|
|
|
EDA_ITEM( NOT_USED ), // Never added to anything - just a preview
|
2023-12-03 14:23:57 +00:00
|
|
|
m_frame( aFrame ),
|
|
|
|
m_min( 0.0 ),
|
|
|
|
m_max( 0.0 ),
|
|
|
|
m_current( 0.0 )
|
2023-12-02 10:32:45 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
wxString GetClass() const override { return wxT( "TUNING_STATUS" ); }
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
void Show( int nestLevel, std::ostream& os ) const override {}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VECTOR2I GetPosition() const override { return m_pos; }
|
|
|
|
void SetPosition( const VECTOR2I& aPos ) override { m_pos = aPos; };
|
|
|
|
|
|
|
|
void SetMinMax( double aMin, double aMax )
|
|
|
|
{
|
|
|
|
m_min = aMin;
|
|
|
|
m_minText = m_frame->MessageTextFromValue( m_min, false );
|
|
|
|
m_max = aMax;
|
|
|
|
m_maxText = m_frame->MessageTextFromValue( m_max, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearMinMax()
|
|
|
|
{
|
|
|
|
m_min = 0.0;
|
|
|
|
m_minText = wxT( "---" );
|
|
|
|
m_max = std::numeric_limits<double>::max();
|
|
|
|
m_maxText = wxT( "---" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCurrent( double aCurrent, const wxString& aLabel )
|
|
|
|
{
|
|
|
|
m_current = aCurrent;
|
|
|
|
m_currentText = m_frame->MessageTextFromValue( aCurrent );
|
|
|
|
m_currentLabel = aLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I ViewBBox() const override
|
|
|
|
{
|
|
|
|
BOX2I tmp;
|
|
|
|
|
|
|
|
// this is an edit-time artefact; no reason to try and be smart with the bounding box
|
|
|
|
// (besides, we can't tell the text extents without a view to know what the scale is)
|
|
|
|
tmp.SetMaximum();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override
|
|
|
|
{
|
2023-12-17 13:46:57 +00:00
|
|
|
aLayers[0] = LAYER_UI_START;
|
|
|
|
aLayers[1] = LAYER_UI_START + 1;
|
2023-12-02 10:32:45 +00:00
|
|
|
aCount = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override
|
|
|
|
{
|
2023-12-03 13:20:47 +00:00
|
|
|
KIGFX::GAL* gal = aView->GetGAL();
|
|
|
|
bool viewFlipped = gal->IsFlippedX();
|
2023-12-17 13:46:57 +00:00
|
|
|
bool drawingDropShadows = ( aLayer == LAYER_UI_START );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-17 13:46:57 +00:00
|
|
|
gal->Save();
|
|
|
|
gal->Scale( { 1., 1. } );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-17 13:46:57 +00:00
|
|
|
KIGFX::PREVIEW::TEXT_DIMS headerDims = KIGFX::PREVIEW::GetConstantGlyphHeight( gal, -2 );
|
|
|
|
KIGFX::PREVIEW::TEXT_DIMS textDims = KIGFX::PREVIEW::GetConstantGlyphHeight( gal, -1 );
|
2023-12-03 13:20:47 +00:00
|
|
|
KIFONT::FONT* font = KIFONT::FONT::GetFont();
|
|
|
|
const KIFONT::METRICS& fontMetrics = KIFONT::METRICS::Default();
|
|
|
|
TEXT_ATTRIBUTES textAttrs;
|
|
|
|
|
|
|
|
int glyphWidth = textDims.GlyphSize.x;
|
2023-12-17 13:46:57 +00:00
|
|
|
VECTOR2I margin( KiROUND( glyphWidth * 0.4 ), KiROUND( glyphWidth ) );
|
2023-12-03 13:20:47 +00:00
|
|
|
VECTOR2I size( glyphWidth * 25 + margin.x * 2, headerDims.GlyphSize.y + textDims.GlyphSize.y );
|
|
|
|
VECTOR2I offset( margin.x * 2, -( size.y + margin.y * 2 ) );
|
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
if( drawingDropShadows )
|
2023-12-03 13:20:47 +00:00
|
|
|
{
|
|
|
|
gal->SetIsFill( true );
|
|
|
|
gal->SetIsStroke( true );
|
2023-12-17 13:46:57 +00:00
|
|
|
gal->SetLineWidth( gal->GetScreenWorldMatrix().GetScale().x * 2 );
|
2023-12-03 13:20:47 +00:00
|
|
|
gal->SetStrokeColor( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
|
2023-12-17 13:46:57 +00:00
|
|
|
KIGFX::COLOR4D bgColor( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
|
|
|
|
gal->SetFillColor( bgColor.WithAlpha( 0.9 ) );
|
2023-12-03 13:20:47 +00:00
|
|
|
|
|
|
|
gal->DrawRectangle( GetPosition() + offset - margin,
|
|
|
|
GetPosition() + offset + size + margin );
|
2023-12-17 13:46:57 +00:00
|
|
|
gal->Restore();
|
2023-12-03 13:20:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
COLOR4D bg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
|
|
|
|
COLOR4D normal = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
|
|
|
|
COLOR4D red;
|
|
|
|
|
|
|
|
// Choose a red with reasonable contrasting with the background
|
|
|
|
double bg_h, bg_s, bg_l;
|
|
|
|
bg.ToHSL( bg_h, bg_s, bg_l );
|
|
|
|
red.FromHSL( 0, 1.0, bg_l < 0.5 ? 0.7 : 0.3 );
|
|
|
|
|
|
|
|
if( viewFlipped )
|
|
|
|
textAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT;
|
2023-12-02 10:32:45 +00:00
|
|
|
else
|
2023-12-03 13:20:47 +00:00
|
|
|
textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
|
|
|
|
gal->SetIsFill( false );
|
|
|
|
gal->SetIsStroke( true );
|
|
|
|
gal->SetStrokeColor( normal );
|
|
|
|
textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
|
|
|
|
// Prevent text flipping when view is flipped
|
|
|
|
if( gal->IsFlippedX() )
|
|
|
|
{
|
|
|
|
textAttrs.m_Mirrored = true;
|
|
|
|
textAttrs.m_Halign = GR_TEXT_H_ALIGN_RIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
textAttrs.m_Size = headerDims.GlyphSize;
|
|
|
|
textAttrs.m_StrokeWidth = headerDims.StrokeWidth;
|
|
|
|
|
|
|
|
VECTOR2I textPos = GetPosition() + offset;
|
|
|
|
font->Draw( gal, m_currentLabel, textPos, textAttrs, KIFONT::METRICS::Default() );
|
|
|
|
|
|
|
|
textPos.x += glyphWidth * 11 + margin.x;
|
|
|
|
font->Draw( gal, _( "min" ), textPos, textAttrs, fontMetrics );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-03 13:20:47 +00:00
|
|
|
textPos.x += glyphWidth * 7 + margin.x;
|
|
|
|
font->Draw( gal, _( "max" ), textPos, textAttrs, fontMetrics );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-03 13:20:47 +00:00
|
|
|
textAttrs.m_Size = textDims.GlyphSize;
|
|
|
|
textAttrs.m_StrokeWidth = textDims.StrokeWidth;
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-03 13:20:47 +00:00
|
|
|
textPos = GetPosition() + offset;
|
2023-12-08 19:35:11 +00:00
|
|
|
textPos.y += KiROUND( headerDims.LinePitch * 1.3 );
|
2023-12-03 13:20:47 +00:00
|
|
|
font->Draw( gal, m_currentText, textPos, textAttrs, KIFONT::METRICS::Default() );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-03 13:20:47 +00:00
|
|
|
textPos.x += glyphWidth * 11 + margin.x;
|
|
|
|
gal->SetStrokeColor( m_current < m_min ? red : normal );
|
|
|
|
font->Draw( gal, m_minText, textPos, textAttrs, fontMetrics );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-03 13:20:47 +00:00
|
|
|
textPos.x += glyphWidth * 7 + margin.x;
|
|
|
|
gal->SetStrokeColor( m_current > m_max ? red : normal );
|
|
|
|
font->Draw( gal, m_maxText, textPos, textAttrs, fontMetrics );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
2023-12-17 13:46:57 +00:00
|
|
|
gal->Restore();
|
2023-12-02 10:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EDA_DRAW_FRAME* m_frame;
|
|
|
|
VECTOR2I m_pos;
|
|
|
|
double m_min;
|
|
|
|
double m_max;
|
|
|
|
double m_current;
|
|
|
|
wxString m_currentLabel;
|
|
|
|
wxString m_currentText;
|
|
|
|
wxString m_minText;
|
|
|
|
wxString m_maxText;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
class PCB_TUNING_PATTERN : public PCB_GENERATOR
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const wxString GENERATOR_TYPE;
|
|
|
|
static const wxString DISPLAY_NAME;
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
PCB_TUNING_PATTERN( BOARD_ITEM* aParent = nullptr, PCB_LAYER_ID aLayer = F_Cu,
|
|
|
|
LENGTH_TUNING_MODE aMode = LENGTH_TUNING_MODE::SINGLE );
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-17 12:30:40 +00:00
|
|
|
wxString GetGeneratorType() const override { return wxS( "tuning_pattern" ); }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override
|
|
|
|
{
|
|
|
|
return wxString( _( "Tuning Pattern" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetFriendlyName() const override
|
|
|
|
{
|
|
|
|
return wxString( _( "Tuning Pattern" ) );
|
|
|
|
}
|
|
|
|
|
2023-10-19 00:31:01 +00:00
|
|
|
wxString GetPluralName() const override
|
|
|
|
{
|
|
|
|
return wxString( _( "Tuning Patterns" ) );
|
|
|
|
}
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
static PCB_TUNING_PATTERN* CreateNew( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_CONNECTED_ITEM* aStartItem,
|
2023-12-08 17:00:55 +00:00
|
|
|
LENGTH_TUNING_MODE aMode );
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit,
|
|
|
|
const wxString& aCommitMsg = wxEmptyString, int aCommitFlags = 0 ) override;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
bool MakeEditPoints( std::shared_ptr<EDIT_POINTS> points ) const override;
|
|
|
|
|
|
|
|
bool UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
|
|
|
|
BOARD_COMMIT* aCommit ) override;
|
|
|
|
|
|
|
|
bool UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints ) override;
|
|
|
|
|
|
|
|
void Move( const VECTOR2I& aMoveVector ) override
|
|
|
|
{
|
|
|
|
m_origin += aMoveVector;
|
|
|
|
m_end += aMoveVector;
|
2023-11-09 13:55:00 +00:00
|
|
|
|
2023-11-12 09:17:03 +00:00
|
|
|
if( !this->HasFlag( IN_EDIT ) )
|
|
|
|
{
|
|
|
|
PCB_GROUP::Move( aMoveVector );
|
|
|
|
|
|
|
|
if( m_baseLine )
|
|
|
|
m_baseLine->Move( aMoveVector );
|
|
|
|
|
|
|
|
if( m_baseLineCoupled )
|
|
|
|
m_baseLineCoupled->Move( aMoveVector );
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 22:34:41 +00:00
|
|
|
void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override
|
|
|
|
{
|
2023-11-12 09:17:03 +00:00
|
|
|
if( !this->HasFlag( IN_EDIT ) )
|
|
|
|
{
|
|
|
|
RotatePoint( m_origin, aRotCentre, aAngle );
|
|
|
|
RotatePoint( m_end, aRotCentre, aAngle );
|
|
|
|
PCB_GROUP::Rotate( aRotCentre, aAngle );
|
|
|
|
|
|
|
|
if( m_baseLine )
|
|
|
|
m_baseLine->Rotate( aAngle, aRotCentre );
|
|
|
|
|
|
|
|
if( m_baseLineCoupled )
|
|
|
|
m_baseLineCoupled->Rotate( aAngle, aRotCentre );
|
|
|
|
}
|
2023-10-19 22:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I GetBoundingBox() const override
|
|
|
|
{
|
2024-01-24 12:40:42 +00:00
|
|
|
return getOutline().BBox();
|
2023-10-19 22:34:41 +00:00
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override
|
|
|
|
{
|
|
|
|
aCount = 0;
|
|
|
|
aLayers[aCount++] = LAYER_ANCHOR;
|
2024-01-17 00:34:06 +00:00
|
|
|
aLayers[aCount++] = GetLayer();
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
|
|
|
|
{
|
2024-01-24 12:40:42 +00:00
|
|
|
return getOutline().Collide( aPosition, aAccuracy );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const override
|
|
|
|
{
|
2024-01-16 23:43:11 +00:00
|
|
|
BOX2I sel = aRect;
|
|
|
|
|
|
|
|
if ( aAccuracy )
|
|
|
|
sel.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return sel.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return sel.Intersects( GetBoundingBox() );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I ViewBBox() const override { return GetBoundingBox(); }
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
EDA_ITEM* Clone() const override { return new PCB_TUNING_PATTERN( *this ); }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override final;
|
|
|
|
|
|
|
|
const VECTOR2I& GetEnd() const { return m_end; }
|
|
|
|
void SetEnd( const VECTOR2I& aValue ) { m_end = aValue; }
|
|
|
|
|
|
|
|
int GetEndX() const { return m_end.x; }
|
|
|
|
void SetEndX( int aValue ) { m_end.x = aValue; }
|
|
|
|
|
|
|
|
int GetEndY() const { return m_end.y; }
|
|
|
|
void SetEndY( int aValue ) { m_end.y = aValue; }
|
|
|
|
|
|
|
|
LENGTH_TUNING_MODE GetTuningMode() const { return m_tuningMode; }
|
|
|
|
|
2023-12-11 14:47:32 +00:00
|
|
|
PNS::ROUTER_MODE GetPNSMode()
|
|
|
|
{
|
|
|
|
switch( m_tuningMode )
|
|
|
|
{
|
|
|
|
case LENGTH_TUNING_MODE::SINGLE: return PNS::PNS_MODE_TUNE_SINGLE;
|
|
|
|
case LENGTH_TUNING_MODE::DIFF_PAIR: return PNS::PNS_MODE_TUNE_DIFF_PAIR;
|
|
|
|
case LENGTH_TUNING_MODE::DIFF_PAIR_SKEW: return PNS::PNS_MODE_TUNE_DIFF_PAIR_SKEW;
|
|
|
|
default: return PNS::PNS_MODE_TUNE_SINGLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PNS::MEANDER_SETTINGS& GetSettings() { return m_settings; }
|
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
int GetMinAmplitude() const { return m_settings.m_minAmplitude; }
|
2024-02-09 21:42:36 +00:00
|
|
|
void SetMinAmplitude( int aValue )
|
|
|
|
{
|
|
|
|
aValue = std::max( aValue, 0 );
|
|
|
|
|
|
|
|
m_settings.m_minAmplitude = aValue;
|
|
|
|
|
|
|
|
if( m_settings.m_maxAmplitude < m_settings.m_minAmplitude )
|
|
|
|
m_settings.m_maxAmplitude = m_settings.m_minAmplitude;
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
int GetMaxAmplitude() const { return m_settings.m_maxAmplitude; }
|
2024-02-09 21:42:36 +00:00
|
|
|
void SetMaxAmplitude( int aValue )
|
|
|
|
{
|
|
|
|
aValue = std::max( aValue, 0 );
|
|
|
|
|
|
|
|
m_settings.m_maxAmplitude = aValue;
|
|
|
|
|
|
|
|
if( m_settings.m_maxAmplitude < m_settings.m_minAmplitude )
|
|
|
|
m_settings.m_minAmplitude = m_settings.m_maxAmplitude;
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
PNS::MEANDER_SIDE GetInitialSide() const { return m_settings.m_initialSide; }
|
|
|
|
void SetInitialSide( PNS::MEANDER_SIDE aValue ) { m_settings.m_initialSide = aValue; }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
int GetSpacing() const { return m_settings.m_spacing; }
|
|
|
|
void SetSpacing( int aValue ) { m_settings.m_spacing = aValue; }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2024-02-08 18:14:20 +00:00
|
|
|
std::optional<int> GetTargetLength() const
|
|
|
|
{
|
2024-02-08 22:33:34 +00:00
|
|
|
if( m_settings.m_targetLength.Opt() == PNS::MEANDER_SETTINGS::LENGTH_UNCONSTRAINED )
|
2024-02-08 18:14:20 +00:00
|
|
|
return std::optional<int>();
|
|
|
|
else
|
|
|
|
return m_settings.m_targetLength.Opt();
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2024-02-08 18:14:20 +00:00
|
|
|
void SetTargetLength( std::optional<int> aValue )
|
|
|
|
{
|
|
|
|
if( aValue.has_value() )
|
|
|
|
m_settings.SetTargetLength( aValue.value() );
|
|
|
|
else
|
2024-02-08 22:33:34 +00:00
|
|
|
m_settings.SetTargetLength( PNS::MEANDER_SETTINGS::LENGTH_UNCONSTRAINED );
|
2024-02-08 18:14:20 +00:00
|
|
|
}
|
|
|
|
|
2024-02-08 23:56:05 +00:00
|
|
|
int GetTargetSkew() const { return m_settings.m_targetSkew.Opt(); }
|
|
|
|
void SetTargetSkew( int aValue ) { m_settings.SetTargetSkew( aValue ); }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
bool GetOverrideCustomRules() const { return m_settings.m_overrideCustomRules; }
|
|
|
|
void SetOverrideCustomRules( bool aOverride ) { m_settings.m_overrideCustomRules = aOverride; }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
int GetCornerRadiusPercentage() const { return m_settings.m_cornerRadiusPercentage; }
|
|
|
|
void SetCornerRadiusPercentage( int aValue ) { m_settings.m_cornerRadiusPercentage = aValue; }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
bool IsSingleSided() const { return m_settings.m_singleSided; }
|
|
|
|
void SetSingleSided( bool aValue ) { m_settings.m_singleSided = aValue; }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
bool IsRounded() const { return m_settings.m_cornerStyle == PNS::MEANDER_STYLE_ROUND; }
|
|
|
|
void SetRounded( bool aFlag ) { m_settings.m_cornerStyle = aFlag ? PNS::MEANDER_STYLE_ROUND
|
|
|
|
: PNS::MEANDER_STYLE_CHAMFER; }
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
std::vector<std::pair<wxString, wxVariant>> GetRowData() override
|
|
|
|
{
|
|
|
|
std::vector<std::pair<wxString, wxVariant>> data = PCB_GENERATOR::GetRowData();
|
|
|
|
data.emplace_back( _HKI( "Net" ), m_lastNetName );
|
|
|
|
data.emplace_back( _HKI( "Tuning" ), m_tuningInfo );
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const STRING_ANY_MAP GetProperties() const override;
|
|
|
|
void SetProperties( const STRING_ANY_MAP& aProps ) override;
|
|
|
|
|
|
|
|
void ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame ) override;
|
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
std::vector<EDA_ITEM*> GetPreviewItems( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
|
2023-12-06 13:08:05 +00:00
|
|
|
bool aStatusItemsOnly = false ) override;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
protected:
|
|
|
|
void swapData( BOARD_ITEM* aImage ) override
|
|
|
|
{
|
|
|
|
wxASSERT( aImage->Type() == PCB_GENERATOR_T );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
std::swap( *this, *static_cast<PCB_TUNING_PATTERN*>( aImage ) );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
bool recoverBaseline( PNS::ROUTER* aRouter );
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
bool baselineValid();
|
|
|
|
|
|
|
|
bool initBaseLine( PNS::ROUTER* aRouter, int aLayer, BOARD* aBoard, VECTOR2I& aStart,
|
|
|
|
VECTOR2I& aEnd, NETINFO_ITEM* aNet,
|
|
|
|
std::optional<SHAPE_LINE_CHAIN>& aBaseLine );
|
|
|
|
|
|
|
|
bool initBaseLines( PNS::ROUTER* aRouter, int aLayer, BOARD* aBoard );
|
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
bool removeToBaseline( PNS::ROUTER* aRouter, int aLayer, SHAPE_LINE_CHAIN& aBaseLine );
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
bool resetToBaseline( GENERATOR_TOOL* aTool, int aLayer, SHAPE_LINE_CHAIN& aBaseLine,
|
|
|
|
bool aPrimary );
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2024-01-24 12:40:42 +00:00
|
|
|
SHAPE_LINE_CHAIN getOutline() const;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
protected:
|
2023-10-16 23:27:08 +00:00
|
|
|
VECTOR2I m_end;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
PNS::MEANDER_SETTINGS m_settings;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
std::optional<SHAPE_LINE_CHAIN> m_baseLine;
|
|
|
|
std::optional<SHAPE_LINE_CHAIN> m_baseLineCoupled;
|
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
int m_trackWidth;
|
|
|
|
int m_diffPairGap;
|
2023-10-16 12:12:17 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
LENGTH_TUNING_MODE m_tuningMode;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
wxString m_lastNetName;
|
|
|
|
wxString m_tuningInfo;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
PNS::MEANDER_PLACER_BASE::TUNING_STATUS m_tuningStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static LENGTH_TUNING_MODE tuningFromString( const std::string& aStr )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
|
|
|
if( aStr == "single" )
|
|
|
|
return LENGTH_TUNING_MODE::SINGLE;
|
|
|
|
else if( aStr == "diff_pair" )
|
|
|
|
return LENGTH_TUNING_MODE::DIFF_PAIR;
|
|
|
|
else if( aStr == "diff_pair_skew" )
|
|
|
|
return LENGTH_TUNING_MODE::DIFF_PAIR_SKEW;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxS( "Unknown length tuning token" ) );
|
|
|
|
return LENGTH_TUNING_MODE::SINGLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static std::string tuningToString( const LENGTH_TUNING_MODE aTuning )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
|
|
|
switch( aTuning )
|
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
case LENGTH_TUNING_MODE::SINGLE: return "single";
|
|
|
|
case LENGTH_TUNING_MODE::DIFF_PAIR: return "diff_pair";
|
2023-10-07 03:54:14 +00:00
|
|
|
case LENGTH_TUNING_MODE::DIFF_PAIR_SKEW: return "diff_pair_skew";
|
2023-10-14 12:38:25 +00:00
|
|
|
default: wxFAIL; return "";
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static LENGTH_TUNING_MODE fromPNSMode( PNS::ROUTER_MODE aRouterMode )
|
2023-10-11 16:10:48 +00:00
|
|
|
{
|
|
|
|
switch( aRouterMode )
|
|
|
|
{
|
|
|
|
case PNS::PNS_MODE_TUNE_SINGLE: return LENGTH_TUNING_MODE::SINGLE;
|
|
|
|
case PNS::PNS_MODE_TUNE_DIFF_PAIR: return LENGTH_TUNING_MODE::DIFF_PAIR;
|
|
|
|
case PNS::PNS_MODE_TUNE_DIFF_PAIR_SKEW: return LENGTH_TUNING_MODE::DIFF_PAIR_SKEW;
|
|
|
|
default: return LENGTH_TUNING_MODE::SINGLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static PNS::MEANDER_SIDE sideFromString( const std::string& aStr )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
|
|
|
if( aStr == "default" )
|
|
|
|
return PNS::MEANDER_SIDE_DEFAULT;
|
|
|
|
else if( aStr == "left" )
|
|
|
|
return PNS::MEANDER_SIDE_LEFT;
|
|
|
|
else if( aStr == "right" )
|
|
|
|
return PNS::MEANDER_SIDE_RIGHT;
|
|
|
|
else
|
|
|
|
{
|
2023-10-15 16:02:15 +00:00
|
|
|
wxFAIL_MSG( wxS( "Unknown length-tuning side token" ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
return PNS::MEANDER_SIDE_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static std::string statusToString( const PNS::MEANDER_PLACER_BASE::TUNING_STATUS aStatus )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
|
|
|
switch( aStatus )
|
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
case PNS::MEANDER_PLACER_BASE::TOO_LONG: return "too_long";
|
2023-10-07 03:54:14 +00:00
|
|
|
case PNS::MEANDER_PLACER_BASE::TOO_SHORT: return "too_short";
|
2023-10-14 12:38:25 +00:00
|
|
|
case PNS::MEANDER_PLACER_BASE::TUNED: return "tuned";
|
|
|
|
default: wxFAIL; return "";
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static PNS::MEANDER_PLACER_BASE::TUNING_STATUS statusFromString( const std::string& aStr )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
|
|
|
if( aStr == "too_long" )
|
|
|
|
return PNS::MEANDER_PLACER_BASE::TOO_LONG;
|
|
|
|
else if( aStr == "too_short" )
|
|
|
|
return PNS::MEANDER_PLACER_BASE::TOO_SHORT;
|
|
|
|
else if( aStr == "tuned" )
|
|
|
|
return PNS::MEANDER_PLACER_BASE::TUNED;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxS( "Unknown tuning status token" ) );
|
|
|
|
return PNS::MEANDER_PLACER_BASE::TUNED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static std::string sideToString( const PNS::MEANDER_SIDE aValue )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
|
|
|
switch( aValue )
|
|
|
|
{
|
|
|
|
case PNS::MEANDER_SIDE_DEFAULT: return "default";
|
2023-10-14 12:38:25 +00:00
|
|
|
case PNS::MEANDER_SIDE_LEFT: return "left";
|
|
|
|
case PNS::MEANDER_SIDE_RIGHT: return "right";
|
|
|
|
default: wxFAIL; return "";
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
PCB_TUNING_PATTERN::PCB_TUNING_PATTERN( BOARD_ITEM* aParent, PCB_LAYER_ID aLayer,
|
|
|
|
LENGTH_TUNING_MODE aMode ) :
|
2023-10-14 12:38:25 +00:00
|
|
|
PCB_GENERATOR( aParent, aLayer ),
|
2023-10-16 12:12:17 +00:00
|
|
|
m_trackWidth( 0 ),
|
|
|
|
m_diffPairGap( 0 ),
|
2023-10-14 12:38:25 +00:00
|
|
|
m_tuningMode( aMode ),
|
|
|
|
m_tuningStatus( PNS::MEANDER_PLACER_BASE::TUNING_STATUS::TUNED )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
m_generatorType = GENERATOR_TYPE;
|
|
|
|
m_name = DISPLAY_NAME;
|
|
|
|
m_end = VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 );
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings.m_initialSide = PNS::MEANDER_SIDE_LEFT;
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
static VECTOR2I snapToNearestTrack( const VECTOR2I& aP, BOARD* aBoard, NETINFO_ITEM* aNet,
|
|
|
|
PCB_TRACK** aNearestTrack )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-10-16 12:12:17 +00:00
|
|
|
SEG::ecoord minDist_sq = VECTOR2I::ECOORD_MAX;
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I closestPt = aP;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( PCB_TRACK *track : aBoard->Tracks() )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
if( aNet && track->GetNet() != aNet )
|
|
|
|
continue;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2024-01-31 20:38:05 +00:00
|
|
|
VECTOR2I nearest;
|
|
|
|
|
|
|
|
if( track->Type() == PCB_ARC_T )
|
|
|
|
{
|
|
|
|
PCB_ARC* pcbArc = static_cast<PCB_ARC*>( track );
|
|
|
|
SHAPE_ARC arc( pcbArc->GetStart(), pcbArc->GetMid(), pcbArc->GetEnd(),
|
|
|
|
pcbArc->GetWidth() );
|
|
|
|
|
|
|
|
nearest = arc.NearestPoint( aP );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SEG seg( track->GetStart(), track->GetEnd() );
|
|
|
|
nearest = seg.NearestPoint( aP );
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
SEG::ecoord dist_sq = ( nearest - aP ).SquaredEuclideanNorm();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
if( dist_sq < minDist_sq )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-16 12:12:17 +00:00
|
|
|
minDist_sq = dist_sq;
|
2023-10-14 12:38:25 +00:00
|
|
|
closestPt = nearest;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
if( aNearestTrack )
|
|
|
|
*aNearestTrack = track;
|
|
|
|
}
|
2023-10-12 14:45:33 +00:00
|
|
|
}
|
2023-10-08 13:04:45 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
return closestPt;
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
bool PCB_TUNING_PATTERN::baselineValid()
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
if( m_tuningMode == DIFF_PAIR || m_tuningMode == DIFF_PAIR_SKEW )
|
|
|
|
{
|
|
|
|
return( m_baseLine && m_baseLine->PointCount() > 1
|
|
|
|
&& m_baseLineCoupled && m_baseLineCoupled->PointCount() > 1 );
|
|
|
|
}
|
|
|
|
else
|
2023-10-09 20:55:07 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
return( m_baseLine && m_baseLine->PointCount() > 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
PCB_TUNING_PATTERN* PCB_TUNING_PATTERN::CreateNew( GENERATOR_TOOL* aTool,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_CONNECTED_ITEM* aStartItem,
|
2023-12-08 17:00:55 +00:00
|
|
|
LENGTH_TUNING_MODE aMode )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-01-30 12:45:37 +00:00
|
|
|
BOARD* board = aStartItem->GetBoard();
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
PCB_LAYER_ID layer = aStartItem->GetLayer();
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
PCB_TUNING_PATTERN* pattern = new PCB_TUNING_PATTERN( board, layer, aMode );
|
2023-10-10 10:08:53 +00:00
|
|
|
|
2024-01-30 12:45:37 +00:00
|
|
|
switch( aMode )
|
|
|
|
{
|
|
|
|
case SINGLE: pattern->m_settings = bds.m_SingleTrackMeanderSettings; break;
|
|
|
|
case DIFF_PAIR: pattern->m_settings = bds.m_DiffPairMeanderSettings; break;
|
|
|
|
case DIFF_PAIR_SKEW: pattern->m_settings = bds.m_SkewMeanderSettings; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
constraint = bds.m_DRCEngine->EvalRules( LENGTH_CONSTRAINT, aStartItem, nullptr, layer );
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-12-08 17:00:55 +00:00
|
|
|
if( !constraint.IsNull() )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-12-08 17:00:55 +00:00
|
|
|
if( aMode == DIFF_PAIR_SKEW )
|
2023-11-23 18:41:59 +00:00
|
|
|
pattern->m_settings.SetTargetSkew( constraint.GetValue() );
|
2023-10-09 20:55:07 +00:00
|
|
|
else
|
2023-12-08 17:00:55 +00:00
|
|
|
pattern->m_settings.SetTargetLength( constraint.GetValue() );
|
|
|
|
}
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
pattern->SetFlags( IS_NEW );
|
2023-10-09 21:32:17 +00:00
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
return pattern;
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void PCB_TUNING_PATTERN::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
if( aCommit )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
if( IsNew() )
|
|
|
|
aCommit->Add( this );
|
|
|
|
else
|
|
|
|
aCommit->Modify( this );
|
|
|
|
}
|
2023-10-09 20:48:34 +00:00
|
|
|
|
2023-11-12 09:17:03 +00:00
|
|
|
SetFlags( IN_EDIT );
|
2023-10-22 17:33:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
int layer = GetLayer();
|
|
|
|
PNS::ROUTER* router = aTool->Router();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
aTool->ClearRouterChanges();
|
2023-10-14 12:38:25 +00:00
|
|
|
router->SyncWorld();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
PNS::RULE_RESOLVER* resolver = router->GetRuleResolver();
|
|
|
|
PNS::CONSTRAINT constraint;
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !baselineValid() )
|
|
|
|
initBaseLines( router, layer, aBoard );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2024-01-30 13:17:58 +00:00
|
|
|
if( !m_settings.m_overrideCustomRules )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-01-30 13:17:58 +00:00
|
|
|
PCB_TRACK* track = nullptr;
|
|
|
|
PNS::SEGMENT pnsItem;
|
2023-10-16 12:12:17 +00:00
|
|
|
|
|
|
|
m_origin = snapToNearestTrack( m_origin, aBoard, nullptr, &track );
|
|
|
|
wxCHECK( track, /* void */ );
|
2023-10-14 11:11:46 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
NETINFO_ITEM* net = track->GetNet();
|
2024-01-30 13:17:58 +00:00
|
|
|
|
|
|
|
pnsItem.SetParent( track );
|
|
|
|
pnsItem.SetNet( net );
|
2023-10-14 11:11:46 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_tuningMode == SINGLE )
|
|
|
|
{
|
|
|
|
if( resolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_LENGTH,
|
|
|
|
&pnsItem, nullptr, layer, &constraint ) )
|
|
|
|
{
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings.SetTargetLength( constraint.m_Value );
|
2023-12-16 16:11:45 +00:00
|
|
|
aTool->GetManager()->PostEvent( EVENTS::SelectedItemsModified );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-01-30 13:17:58 +00:00
|
|
|
PCB_TRACK* coupledTrack = nullptr;
|
|
|
|
PNS::SEGMENT pnsCoupledItem;
|
2023-10-15 21:45:18 +00:00
|
|
|
NETINFO_ITEM* coupledNet = aBoard->DpCoupledNet( net );
|
2024-01-30 13:17:58 +00:00
|
|
|
|
|
|
|
if( coupledNet )
|
|
|
|
snapToNearestTrack( m_origin, aBoard, coupledNet, &coupledTrack );
|
|
|
|
|
|
|
|
pnsCoupledItem.SetParent( coupledTrack );
|
|
|
|
pnsCoupledItem.SetNet( coupledNet );
|
2023-10-14 11:11:46 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR )
|
2023-10-14 11:11:46 +00:00
|
|
|
{
|
|
|
|
if( resolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_LENGTH,
|
2024-01-30 13:17:58 +00:00
|
|
|
&pnsItem, &pnsCoupledItem, layer, &constraint ) )
|
2023-10-14 11:11:46 +00:00
|
|
|
{
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings.SetTargetLength( constraint.m_Value );
|
2023-12-16 16:11:45 +00:00
|
|
|
aTool->GetManager()->PostEvent( EVENTS::SelectedItemsModified );
|
2023-10-14 11:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
if( resolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_DIFF_PAIR_SKEW,
|
2024-01-30 13:17:58 +00:00
|
|
|
&pnsItem, &pnsCoupledItem, layer, &constraint ) )
|
2023-10-14 11:11:46 +00:00
|
|
|
{
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings.m_targetSkew = constraint.m_Value;
|
2023-12-16 16:11:45 +00:00
|
|
|
aTool->GetManager()->PostEvent( EVENTS::SelectedItemsModified );
|
2023-10-14 11:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static PNS::LINKED_ITEM* pickSegment( PNS::ROUTER* aRouter, const VECTOR2I& aWhere, int aLayer,
|
|
|
|
VECTOR2I& aPointOut )
|
|
|
|
{
|
2023-12-21 12:58:37 +00:00
|
|
|
int maxSlopRadius = aRouter->Sizes().Clearance() + aRouter->Sizes().TrackWidth() / 2;
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static const int candidateCount = 2;
|
|
|
|
PNS::LINKED_ITEM* prioritized[candidateCount];
|
|
|
|
SEG::ecoord dist[candidateCount];
|
|
|
|
VECTOR2I point[candidateCount];
|
|
|
|
|
|
|
|
for( int i = 0; i < candidateCount; i++ )
|
|
|
|
{
|
|
|
|
prioritized[i] = nullptr;
|
|
|
|
dist[i] = VECTOR2I::ECOORD_MAX;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
auto haveCandidates =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
for( PNS::ITEM* item : prioritized )
|
2023-10-09 20:59:55 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
if( item )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-21 12:58:37 +00:00
|
|
|
for( int slopRadius : { 0, maxSlopRadius } )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-12-21 12:58:37 +00:00
|
|
|
PNS::ITEM_SET candidates = aRouter->QueryHoverItems( aWhere, slopRadius );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( PNS::ITEM* item : candidates.Items() )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !item->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::ARC_T ) )
|
|
|
|
continue;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !item->IsRoutable() )
|
|
|
|
continue;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !item->Layers().Overlaps( aLayer ) )
|
|
|
|
continue;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINKED_ITEM* linked = static_cast<PNS::LINKED_ITEM*>( item );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( item->Kind() & PNS::ITEM::ARC_T )
|
|
|
|
{
|
2024-01-31 20:38:05 +00:00
|
|
|
PNS::ARC* pnsArc = static_cast<PNS::ARC*>( item );
|
|
|
|
|
|
|
|
VECTOR2I nearest = pnsArc->Arc().NearestPoint( aWhere );
|
|
|
|
SEG::ecoord d0 = ( nearest - aWhere ).SquaredEuclideanNorm();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( d0 <= dist[1] )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
prioritized[1] = linked;
|
|
|
|
dist[1] = d0;
|
2024-01-31 20:38:05 +00:00
|
|
|
point[1] = nearest;
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
else if( item->Kind() & PNS::ITEM::SEGMENT_T )
|
|
|
|
{
|
|
|
|
PNS::SEGMENT* segm = static_cast<PNS::SEGMENT*>( item );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I nearest = segm->CLine().NearestPoint( aWhere, false );
|
|
|
|
SEG::ecoord dd = ( aWhere - nearest ).SquaredEuclideanNorm();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( dd <= dist[1] )
|
|
|
|
{
|
|
|
|
prioritized[1] = segm;
|
|
|
|
dist[1] = dd;
|
|
|
|
point[1] = nearest;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( haveCandidates() )
|
|
|
|
break;
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINKED_ITEM* rv = nullptr;
|
|
|
|
|
|
|
|
for( int i = 0; i < candidateCount; i++ )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINKED_ITEM* item = prioritized[i];
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( item && ( aLayer < 0 || item->Layers().Overlaps( aLayer ) ) )
|
|
|
|
{
|
|
|
|
rv = item;
|
|
|
|
aPointOut = point[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2023-10-08 13:04:45 +00:00
|
|
|
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static std::optional<PNS::LINE> getPNSLine( const VECTOR2I& aStart, const VECTOR2I& aEnd,
|
|
|
|
PNS::ROUTER* router, int layer, VECTOR2I& aStartOut,
|
|
|
|
VECTOR2I& aEndOut )
|
|
|
|
{
|
|
|
|
PNS::NODE* world = router->GetWorld();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINKED_ITEM* startItem = pickSegment( router, aStart, layer, aStartOut );
|
|
|
|
PNS::LINKED_ITEM* endItem = pickSegment( router, aEnd, layer, aEndOut );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
//wxCHECK( startItem && endItem, std::nullopt );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
for( PNS::LINKED_ITEM* testItem : { startItem, endItem } )
|
|
|
|
{
|
|
|
|
if( !testItem )
|
|
|
|
continue;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
PNS::LINE line = world->AssembleLine( testItem, nullptr, false, false );
|
|
|
|
SHAPE_LINE_CHAIN oldChain = line.CLine();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
if( oldChain.PointOnEdge( aStartOut, 1 ) && oldChain.PointOnEdge( aEndOut, 1 ) )
|
|
|
|
return line;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
return std::nullopt;
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
bool PCB_TUNING_PATTERN::initBaseLine( PNS::ROUTER* aRouter, int aLayer, BOARD* aBoard,
|
|
|
|
VECTOR2I& aStart, VECTOR2I& aEnd, NETINFO_ITEM* aNet,
|
|
|
|
std::optional<SHAPE_LINE_CHAIN>& aBaseLine )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
PNS::NODE* world = aRouter->GetWorld();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
aStart = snapToNearestTrack( aStart, aBoard, aNet, nullptr );
|
|
|
|
aEnd = snapToNearestTrack( aEnd, aBoard, aNet, nullptr );
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I startSnapPoint, endSnapPoint;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINKED_ITEM* startItem = pickSegment( aRouter, aStart, aLayer, startSnapPoint );
|
|
|
|
PNS::LINKED_ITEM* endItem = pickSegment( aRouter, aEnd, aLayer, endSnapPoint );
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxASSERT( startItem );
|
|
|
|
wxASSERT( endItem );
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !startItem || !endItem || startSnapPoint == endSnapPoint )
|
|
|
|
return false;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-22 16:06:15 +00:00
|
|
|
PNS::LINE line = world->AssembleLine( startItem );
|
2023-10-14 12:38:25 +00:00
|
|
|
const SHAPE_LINE_CHAIN& chain = line.CLine();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxASSERT( line.ContainsLink( endItem ) );
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxASSERT( chain.PointOnEdge( startSnapPoint, 1 ) );
|
|
|
|
wxASSERT( chain.PointOnEdge( endSnapPoint, 1 ) );
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN pre;
|
|
|
|
SHAPE_LINE_CHAIN mid;
|
|
|
|
SHAPE_LINE_CHAIN post;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
chain.Split( startSnapPoint, endSnapPoint, pre, mid, post );
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aBaseLine = mid;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-12 14:45:33 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
bool PCB_TUNING_PATTERN::initBaseLines( PNS::ROUTER* aRouter, int aLayer, BOARD* aBoard )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
m_baseLineCoupled.reset();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
PCB_TRACK* track = nullptr;
|
|
|
|
|
|
|
|
m_origin = snapToNearestTrack( m_origin, aBoard, nullptr, &track );
|
|
|
|
wxCHECK( track, false );
|
|
|
|
|
|
|
|
NETINFO_ITEM* net = track->GetNet();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !initBaseLine( aRouter, aLayer, aBoard, m_origin, m_end, net, m_baseLine ) )
|
|
|
|
return false;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
// Generate both baselines even if we're skewing. We need the coupled baseline to run the
|
|
|
|
// DRC rules against.
|
|
|
|
if( m_tuningMode == DIFF_PAIR || m_tuningMode == DIFF_PAIR_SKEW )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-15 21:45:18 +00:00
|
|
|
if( NETINFO_ITEM* coupledNet = aBoard->DpCoupledNet( net ) )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-16 12:12:17 +00:00
|
|
|
VECTOR2I coupledStart = snapToNearestTrack( m_origin, aBoard, coupledNet, nullptr );
|
|
|
|
VECTOR2I coupledEnd = snapToNearestTrack( m_end, aBoard, coupledNet, nullptr );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return initBaseLine( aRouter, aLayer, aBoard, coupledStart, coupledEnd, coupledNet,
|
|
|
|
m_baseLineCoupled );
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return false;
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
bool PCB_TUNING_PATTERN::removeToBaseline( PNS::ROUTER* aRouter, int aLayer,
|
2023-10-18 13:50:48 +00:00
|
|
|
SHAPE_LINE_CHAIN& aBaseLine )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
VECTOR2I startSnapPoint, endSnapPoint;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
std::optional<PNS::LINE> pnsLine = getPNSLine( aBaseLine.CPoint( 0 ), aBaseLine.CPoint( -1 ),
|
|
|
|
aRouter, aLayer, startSnapPoint, endSnapPoint );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
wxCHECK( pnsLine, false );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN pre;
|
|
|
|
SHAPE_LINE_CHAIN mid;
|
|
|
|
SHAPE_LINE_CHAIN post;
|
|
|
|
pnsLine->CLine().Split( startSnapPoint, endSnapPoint, pre, mid, post );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( PNS::LINKED_ITEM* li : pnsLine->Links() )
|
|
|
|
aRouter->GetInterface()->RemoveItem( li );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aRouter->GetWorld()->Remove( *pnsLine );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN straightChain;
|
|
|
|
straightChain.Append( pre );
|
|
|
|
straightChain.Append( aBaseLine );
|
|
|
|
straightChain.Append( post );
|
|
|
|
straightChain.Simplify();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINE straightLine( *pnsLine, straightChain );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aRouter->GetWorld()->Add( straightLine, false );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( PNS::LINKED_ITEM* li : straightLine.Links() )
|
|
|
|
aRouter->GetInterface()->AddItem( li );
|
2023-12-01 05:44:07 +00:00
|
|
|
|
|
|
|
return true;
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void PCB_TUNING_PATTERN::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-12-01 05:44:07 +00:00
|
|
|
SetFlags( IN_EDIT );
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aTool->Router()->SyncWorld();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::ROUTER* router = aTool->Router();
|
|
|
|
int layer = GetLayer();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
// Ungroup first so that undo works
|
|
|
|
if( !GetItems().empty() )
|
|
|
|
{
|
2023-12-17 15:34:33 +00:00
|
|
|
PCB_GENERATOR* group = this;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* member : group->GetItems() )
|
2023-12-17 15:34:33 +00:00
|
|
|
aCommit->Stage( member, CHT_UNGROUP );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
group->GetItems().clear();
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aCommit->Remove( this );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
aTool->ClearRouterChanges();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( baselineValid() )
|
|
|
|
{
|
2023-12-01 05:44:07 +00:00
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
success &= removeToBaseline( router, layer, *m_baseLine );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR )
|
2023-12-01 05:44:07 +00:00
|
|
|
success &= removeToBaseline( router, layer, *m_baseLineCoupled );
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
recoverBaseline( router );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
const std::vector<GENERATOR_PNS_CHANGES>& allPnsChanges = aTool->GetRouterChanges();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
for( const GENERATOR_PNS_CHANGES& pnsChanges : allPnsChanges )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-11-28 19:18:33 +00:00
|
|
|
const std::set<BOARD_ITEM*> routerRemovedItems = pnsChanges.removedItems;
|
|
|
|
const std::set<BOARD_ITEM*> routerAddedItems = pnsChanges.addedItems;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
/*std::cout << "Push commits << " << allPnsChanges.size() << " routerRemovedItems "
|
2023-11-28 17:55:37 +00:00
|
|
|
<< routerRemovedItems.size() << " routerAddedItems " << routerAddedItems.size()
|
|
|
|
<< " m_removedItems " << m_removedItems.size() << std::endl;*/
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : routerRemovedItems )
|
|
|
|
{
|
|
|
|
item->ClearSelected();
|
|
|
|
aCommit->Remove( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : routerAddedItems )
|
|
|
|
aCommit->Add( item );
|
|
|
|
}
|
2023-12-16 16:11:45 +00:00
|
|
|
|
|
|
|
aCommit->Push( "Remove Tuning Pattern" );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
bool PCB_TUNING_PATTERN::recoverBaseline( PNS::ROUTER* aRouter )
|
|
|
|
{
|
|
|
|
PNS::SOLID queryItem;
|
|
|
|
|
2024-01-24 12:40:42 +00:00
|
|
|
SHAPE_LINE_CHAIN* chain = static_cast<SHAPE_LINE_CHAIN*>( getOutline().Clone() );
|
|
|
|
queryItem.SetShape( chain ); // PNS::SOLID takes ownership
|
2023-11-28 17:55:37 +00:00
|
|
|
queryItem.SetLayer( m_layer );
|
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
int lineWidth = 0;
|
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
PNS::NODE::OBSTACLES obstacles;
|
|
|
|
PNS::COLLISION_SEARCH_OPTIONS opts;
|
|
|
|
opts.m_useClearanceEpsilon = false;
|
|
|
|
|
|
|
|
PNS::NODE* world = aRouter->GetWorld();
|
|
|
|
PNS::NODE* branch = world->Branch();
|
|
|
|
|
|
|
|
branch->QueryColliding( &queryItem, obstacles, opts );
|
|
|
|
|
|
|
|
for( const PNS::OBSTACLE& obs : obstacles )
|
|
|
|
{
|
|
|
|
PNS::ITEM* item = obs.m_item;
|
|
|
|
|
|
|
|
if( !item->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::ARC_T ) )
|
|
|
|
continue;
|
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
if( PNS::LINKED_ITEM* li = dynamic_cast<PNS::LINKED_ITEM*>( item ) )
|
|
|
|
{
|
|
|
|
if( lineWidth == 0 || li->Width() < lineWidth )
|
|
|
|
lineWidth = li->Width();
|
|
|
|
}
|
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
if( chain->PointInside( item->Anchor( 0 ), 10 )
|
|
|
|
&& chain->PointInside( item->Anchor( 1 ), 10 ) )
|
|
|
|
{
|
2023-12-01 05:44:07 +00:00
|
|
|
branch->Remove( item );
|
2023-11-28 17:55:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
if( lineWidth == 0 )
|
|
|
|
lineWidth = pcbIUScale.mmToIU( 0.1 ); // Fallback
|
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
if( baselineValid() )
|
|
|
|
{
|
2023-12-14 15:29:42 +00:00
|
|
|
NETINFO_ITEM* recoverNet = GetBoard()->FindNet( m_lastNetName );
|
|
|
|
PNS::LINE recoverLine;
|
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
recoverLine.SetLayer( m_layer );
|
|
|
|
recoverLine.SetWidth( lineWidth );
|
|
|
|
recoverLine.Line() = *m_baseLine;
|
2023-12-14 15:29:42 +00:00
|
|
|
recoverLine.SetNet( recoverNet );
|
2023-11-28 17:55:37 +00:00
|
|
|
branch->Add( recoverLine, false );
|
|
|
|
|
|
|
|
if( m_tuningMode == DIFF_PAIR || m_tuningMode == DIFF_PAIR_SKEW )
|
|
|
|
{
|
2023-12-14 15:29:42 +00:00
|
|
|
NETINFO_ITEM* recoverCoupledNet = GetBoard()->DpCoupledNet( recoverNet );
|
2023-11-28 17:55:37 +00:00
|
|
|
PNS::LINE recoverLineCoupled;
|
2023-12-14 15:29:42 +00:00
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
recoverLineCoupled.SetLayer( m_layer );
|
|
|
|
recoverLineCoupled.SetWidth( lineWidth );
|
|
|
|
recoverLineCoupled.Line() = *m_baseLineCoupled;
|
2023-12-14 15:29:42 +00:00
|
|
|
recoverLineCoupled.SetNet( recoverCoupledNet );
|
2023-11-28 17:55:37 +00:00
|
|
|
branch->Add( recoverLineCoupled, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aRouter->CommitRouting( branch );
|
|
|
|
|
|
|
|
//wxLogWarning( "PNS baseline recovered" );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
bool PCB_TUNING_PATTERN::resetToBaseline( GENERATOR_TOOL* aTool, int aLayer,
|
|
|
|
SHAPE_LINE_CHAIN& aBaseLine, bool aPrimary )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-02-19 15:00:50 +00:00
|
|
|
PNS_KICAD_IFACE* iface = aTool->GetInterface();
|
|
|
|
PNS::ROUTER* router = aTool->Router();
|
|
|
|
PNS::NODE* world = router->GetWorld();
|
|
|
|
VECTOR2I startSnapPoint, endSnapPoint;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
std::optional<PNS::LINE> pnsLine = getPNSLine( aBaseLine.CPoint( 0 ), aBaseLine.CPoint( -1 ),
|
|
|
|
router, aLayer, startSnapPoint, endSnapPoint );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
if( !pnsLine )
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
//recoverBaseline( aRouter );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PNS::NODE* branch = world->Branch();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN straightChain;
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN pre, mid, post;
|
|
|
|
pnsLine->CLine().Split( startSnapPoint, endSnapPoint, pre, mid, post );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
straightChain.Append( pre );
|
|
|
|
straightChain.Append( aBaseLine );
|
|
|
|
straightChain.Append( post );
|
|
|
|
straightChain.Simplify();
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-11-28 17:55:37 +00:00
|
|
|
branch->Remove( *pnsLine );
|
2023-10-09 20:48:34 +00:00
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
SHAPE_LINE_CHAIN newLineChain;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( aPrimary )
|
|
|
|
{
|
|
|
|
m_origin = straightChain.NearestPoint( m_origin );
|
|
|
|
m_end = straightChain.NearestPoint( m_end );
|
|
|
|
|
|
|
|
// Don't allow points too close
|
|
|
|
if( ( m_end - m_origin ).EuclideanNorm() < pcbIUScale.mmToIU( 0.1 ) )
|
|
|
|
{
|
|
|
|
m_origin = startSnapPoint;
|
|
|
|
m_end = endSnapPoint;
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN pre, mid, post;
|
|
|
|
straightChain.Split( m_origin, m_end, pre, mid, post );
|
2023-10-12 16:09:34 +00:00
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
newLineChain.Append( pre );
|
|
|
|
newLineChain.Append( mid );
|
|
|
|
newLineChain.Append( post );
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
m_baseLine = mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VECTOR2I start = straightChain.NearestPoint( m_origin );
|
|
|
|
VECTOR2I end = straightChain.NearestPoint( m_end );
|
2023-10-12 16:09:34 +00:00
|
|
|
|
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN pre, mid, post;
|
|
|
|
straightChain.Split( start, end, pre, mid, post );
|
2023-10-12 16:09:34 +00:00
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
newLineChain.Append( pre );
|
|
|
|
newLineChain.Append( mid );
|
|
|
|
newLineChain.Append( post );
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
m_baseLineCoupled = mid;
|
2023-10-12 16:09:34 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
PNS::LINE newLine( *pnsLine, newLineChain );
|
|
|
|
|
|
|
|
branch->Add( newLine, false );
|
2023-12-16 16:11:45 +00:00
|
|
|
router->CommitRouting( branch );
|
2023-11-28 17:55:37 +00:00
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
int clearance = router->GetRuleResolver()->Clearance( &newLine, nullptr );
|
|
|
|
|
|
|
|
iface->DisplayItem( &newLine, clearance, true, PNS_COLLISION );
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-09 20:48:34 +00:00
|
|
|
|
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
bool PCB_TUNING_PATTERN::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-02-19 15:00:50 +00:00
|
|
|
if( !( GetFlags() & IN_EDIT ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
KIGFX::VIEW* view = aTool->GetManager()->GetView();
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::ROUTER* router = aTool->Router();
|
|
|
|
PNS_KICAD_IFACE* iface = aTool->GetInterface();
|
|
|
|
int layer = GetLayer();
|
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
auto hideRemovedItems = [&]( bool aHide )
|
|
|
|
{
|
|
|
|
if( view )
|
|
|
|
{
|
|
|
|
for( const GENERATOR_PNS_CHANGES& pnsCommit : aTool->GetRouterChanges() )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : pnsCommit.removedItems )
|
|
|
|
{
|
|
|
|
if( view )
|
|
|
|
view->Hide( item, aHide, aHide );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
iface->SetStartLayer( layer );
|
2023-10-11 14:50:15 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( router->RoutingInProgress() )
|
|
|
|
{
|
|
|
|
router->StopRouting();
|
2023-10-09 20:48:34 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !baselineValid() )
|
|
|
|
{
|
|
|
|
initBaseLines( router, layer, aBoard );
|
|
|
|
}
|
|
|
|
else
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-12-16 16:11:45 +00:00
|
|
|
if( resetToBaseline( aTool, layer, *m_baseLine, true ) )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
m_origin = m_baseLine->CPoint( 0 );
|
|
|
|
m_end = m_baseLine->CPoint( -1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-11-28 17:55:37 +00:00
|
|
|
//initBaseLines( router, layer, aBoard );
|
2023-10-14 12:38:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-12-16 16:11:45 +00:00
|
|
|
if( !resetToBaseline( aTool, layer, *m_baseLineCoupled, false ) )
|
2023-10-15 13:13:32 +00:00
|
|
|
{
|
|
|
|
initBaseLines( router, layer, aBoard );
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
hideRemovedItems( true );
|
2023-10-14 12:38:25 +00:00
|
|
|
// Snap points
|
|
|
|
VECTOR2I startSnapPoint, endSnapPoint;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINKED_ITEM* startItem = pickSegment( router, m_origin, layer, startSnapPoint );
|
|
|
|
PNS::LINKED_ITEM* endItem = pickSegment( router, m_end, layer, endSnapPoint );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxASSERT( startItem );
|
|
|
|
wxASSERT( endItem );
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !startItem || !endItem )
|
|
|
|
return false;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-11 14:47:32 +00:00
|
|
|
router->SetMode( GetPNSMode() );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !router->StartRouting( startSnapPoint, startItem, layer ) )
|
2023-11-28 17:55:37 +00:00
|
|
|
{
|
|
|
|
//recoverBaseline( router );
|
2023-10-14 12:38:25 +00:00
|
|
|
return false;
|
2023-11-28 17:55:37 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
PNS::MEANDER_PLACER_BASE* placer = static_cast<PNS::MEANDER_PLACER_BASE*>( router->Placer() );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-12 09:17:03 +00:00
|
|
|
m_settings.m_keepEndpoints = true; // Required for re-grouping
|
2023-10-16 23:27:08 +00:00
|
|
|
placer->UpdateSettings( m_settings );
|
2023-11-28 17:55:37 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
router->Move( m_end, nullptr );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
if( PNS::DP_MEANDER_PLACER* dpPlacer = dynamic_cast<PNS::DP_MEANDER_PLACER*>( placer ) )
|
|
|
|
{
|
|
|
|
m_trackWidth = dpPlacer->GetOriginPair().Width();
|
|
|
|
m_diffPairGap = dpPlacer->GetOriginPair().Gap();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_trackWidth = startItem->Width();
|
|
|
|
m_diffPairGap = router->Sizes().DiffPairGap();
|
|
|
|
}
|
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings = placer->MeanderSettings();
|
2023-10-14 12:38:25 +00:00
|
|
|
m_lastNetName = iface->GetNetName( startItem->Net() );
|
|
|
|
m_tuningStatus = placer->TuningStatus();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-17 12:03:38 +00:00
|
|
|
wxString statusMessage;
|
|
|
|
|
|
|
|
switch ( m_tuningStatus )
|
|
|
|
{
|
|
|
|
case PNS::MEANDER_PLACER_BASE::TOO_LONG: statusMessage = _( "too long" ); break;
|
|
|
|
case PNS::MEANDER_PLACER_BASE::TOO_SHORT: statusMessage = _( "too short" ); break;
|
|
|
|
case PNS::MEANDER_PLACER_BASE::TUNED: statusMessage = _( "tuned" ); break;
|
|
|
|
default: statusMessage = _( "unknown" ); break;
|
|
|
|
}
|
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
wxString result;
|
|
|
|
EDA_UNITS userUnits = EDA_UNITS::MILLIMETRES;
|
|
|
|
|
|
|
|
if( aTool->GetManager()->GetSettings() )
|
|
|
|
userUnits = static_cast<EDA_UNITS>( aTool->GetManager()->GetSettings()->m_System.units );
|
|
|
|
|
|
|
|
result = EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, userUnits,
|
|
|
|
(double) placer->TuningResult() );
|
|
|
|
|
|
|
|
m_tuningInfo.Printf( wxS( "%s (%s)" ), result, statusMessage );
|
2023-10-17 12:03:38 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-12 16:53:26 +00:00
|
|
|
|
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit,
|
2023-10-18 13:50:48 +00:00
|
|
|
const wxString& aCommitMsg, int aCommitFlags )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-02-19 15:00:50 +00:00
|
|
|
if( !( GetFlags() & IN_EDIT ) )
|
|
|
|
return;
|
|
|
|
|
2023-11-12 09:17:03 +00:00
|
|
|
ClearFlags( IN_EDIT );
|
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
KIGFX::VIEW* view = aTool->GetManager()->GetView();
|
2023-10-16 12:43:52 +00:00
|
|
|
PNS::ROUTER* router = aTool->Router();
|
2024-02-19 15:00:50 +00:00
|
|
|
PNS_KICAD_IFACE* iface = aTool->GetInterface();
|
2024-01-24 12:40:42 +00:00
|
|
|
SHAPE_LINE_CHAIN bounds = getOutline();
|
2023-10-22 16:06:15 +00:00
|
|
|
int epsilon = aBoard->GetDesignSettings().GetDRCEpsilon();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
iface->EraseView();
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( router->RoutingInProgress() )
|
|
|
|
{
|
2024-01-02 14:54:11 +00:00
|
|
|
bool forceFinish = true;
|
|
|
|
bool forceCommit = false;
|
|
|
|
|
|
|
|
router->FixRoute( m_end, nullptr, forceFinish, forceCommit );
|
2023-10-14 12:38:25 +00:00
|
|
|
router->StopRouting();
|
2023-11-28 17:55:37 +00:00
|
|
|
}
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
const std::vector<GENERATOR_PNS_CHANGES>& pnsCommits = aTool->GetRouterChanges();
|
2023-11-28 17:55:37 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
for( const GENERATOR_PNS_CHANGES& pnsCommit : pnsCommits )
|
2023-11-28 17:55:37 +00:00
|
|
|
{
|
|
|
|
const std::set<BOARD_ITEM*> routerRemovedItems = pnsCommit.removedItems;
|
|
|
|
const std::set<BOARD_ITEM*> routerAddedItems = pnsCommit.addedItems;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-11-28 19:18:33 +00:00
|
|
|
//std::cout << "Push commits << " << allPnsChanges.size() << " routerRemovedItems "
|
2023-11-28 17:55:37 +00:00
|
|
|
// << routerRemovedItems.size() << " routerAddedItems " << routerAddedItems.size()
|
|
|
|
// << " m_removedItems " << m_removedItems.size() << std::endl;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* item : routerRemovedItems )
|
|
|
|
{
|
2023-12-16 16:11:45 +00:00
|
|
|
if( view )
|
|
|
|
view->Hide( item, false );
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aCommit->Remove( item );
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* item : routerAddedItems )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-11-12 09:17:03 +00:00
|
|
|
if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item ) )
|
2023-10-16 12:43:52 +00:00
|
|
|
{
|
2024-01-31 18:44:56 +00:00
|
|
|
if( bounds.PointInside( track->GetStart(), epsilon )
|
2023-11-12 09:17:03 +00:00
|
|
|
&& bounds.PointInside( track->GetEnd(), epsilon ) )
|
|
|
|
{
|
|
|
|
AddItem( item );
|
2023-12-17 15:34:33 +00:00
|
|
|
aCommit->Stage( item, CHT_GROUP );
|
2023-11-12 09:17:03 +00:00
|
|
|
}
|
2023-10-16 12:43:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aCommit->Add( item );
|
|
|
|
}
|
2023-11-28 17:55:37 +00:00
|
|
|
}
|
2023-12-16 16:11:45 +00:00
|
|
|
|
|
|
|
if( aCommitMsg.IsEmpty() )
|
|
|
|
aCommit->Push( _( "Edit Tuning Pattern" ), aCommitFlags );
|
|
|
|
else
|
|
|
|
aCommit->Push( aCommitMsg, aCommitFlags );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
void PCB_TUNING_PATTERN::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-02-19 15:00:50 +00:00
|
|
|
if( !( GetFlags() & IN_EDIT ) )
|
|
|
|
return;
|
|
|
|
|
2023-11-12 09:17:03 +00:00
|
|
|
ClearFlags( IN_EDIT );
|
|
|
|
|
2024-02-19 15:00:50 +00:00
|
|
|
PNS_KICAD_IFACE* iface = aTool->GetInterface();
|
|
|
|
|
|
|
|
iface->EraseView();
|
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
if( KIGFX::VIEW* view = aTool->GetManager()->GetView() )
|
2023-12-11 16:01:29 +00:00
|
|
|
{
|
2023-12-16 16:11:45 +00:00
|
|
|
for( const GENERATOR_PNS_CHANGES& pnsCommit : aTool->GetRouterChanges() )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : pnsCommit.removedItems )
|
|
|
|
view->Hide( item, false );
|
|
|
|
}
|
2023-12-11 16:01:29 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aTool->Router()->StopRouting();
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( aCommit )
|
|
|
|
aCommit->Revert();
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
bool PCB_TUNING_PATTERN::MakeEditPoints( std::shared_ptr<EDIT_POINTS> points ) const
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
VECTOR2I centerlineOffset;
|
2023-12-01 05:44:07 +00:00
|
|
|
VECTOR2I centerlineOffsetEnd;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR && m_baseLineCoupled && m_baseLineCoupled->SegmentCount() > 0 )
|
2023-12-01 05:44:07 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
centerlineOffset = ( m_baseLineCoupled->CPoint( 0 ) - m_origin ) / 2;
|
2023-12-01 05:44:07 +00:00
|
|
|
centerlineOffsetEnd = ( m_baseLineCoupled->CPoint( -1 ) - m_end ) / 2;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
points->AddPoint( m_origin + centerlineOffset );
|
2023-12-01 05:44:07 +00:00
|
|
|
points->AddPoint( m_end + centerlineOffsetEnd );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SEG base = m_baseLine && m_baseLine->SegmentCount() > 0 ? m_baseLine->CSegment( 0 )
|
|
|
|
: SEG( m_origin, m_end );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
base.A += centerlineOffset;
|
|
|
|
base.B += centerlineOffset;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
int amplitude = m_settings.m_maxAmplitude + KiROUND( m_trackWidth / 2.0 );
|
2023-10-16 12:12:17 +00:00
|
|
|
|
|
|
|
if( m_tuningMode == DIFF_PAIR )
|
2023-12-01 05:44:07 +00:00
|
|
|
amplitude += m_trackWidth + m_diffPairGap;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
if( m_settings.m_initialSide == -1 )
|
2023-10-16 12:12:17 +00:00
|
|
|
amplitude *= -1;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
VECTOR2I widthHandleOffset = ( base.B - base.A ).Perpendicular().Resize( amplitude );
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
points->AddPoint( base.A + widthHandleOffset );
|
|
|
|
points->Point( 2 ).SetGridConstraint( IGNORE_GRID );
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I spacingHandleOffset =
|
2023-10-16 23:27:08 +00:00
|
|
|
widthHandleOffset + ( base.B - base.A ).Resize( KiROUND( m_settings.m_spacing * 1.5 ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
points->AddPoint( base.A + spacingHandleOffset );
|
|
|
|
points->Point( 3 ).SetGridConstraint( IGNORE_GRID );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
bool PCB_TUNING_PATTERN::UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
|
|
|
|
BOARD_COMMIT* aCommit )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
VECTOR2I centerlineOffset;
|
2023-12-01 05:44:07 +00:00
|
|
|
VECTOR2I centerlineOffsetEnd;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR && m_baseLineCoupled && m_baseLineCoupled->SegmentCount() > 0 )
|
2023-12-01 05:44:07 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
centerlineOffset = ( m_baseLineCoupled->CPoint( 0 ) - m_origin ) / 2;
|
2023-12-01 05:44:07 +00:00
|
|
|
centerlineOffsetEnd = ( m_baseLineCoupled->CPoint( -1 ) - m_end ) / 2;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SEG base = m_baseLine && m_baseLine->SegmentCount() > 0 ? m_baseLine->CSegment( 0 )
|
|
|
|
: SEG( m_origin, m_end );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
base.A += centerlineOffset;
|
|
|
|
base.B += centerlineOffset;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
m_origin = aEditPoints->Point( 0 ).GetPosition() - centerlineOffset;
|
2023-12-01 05:44:07 +00:00
|
|
|
m_end = aEditPoints->Point( 1 ).GetPosition() - centerlineOffsetEnd;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
|
|
|
if( aEditPoints->Point( 2 ).IsActive() )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I wHandle = aEditPoints->Point( 2 ).GetPosition();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
int value = base.LineDistance( wHandle );
|
2023-10-16 12:12:17 +00:00
|
|
|
|
|
|
|
value -= KiROUND( m_trackWidth / 2.0 );
|
|
|
|
|
|
|
|
if( m_tuningMode == DIFF_PAIR )
|
2023-12-01 05:44:07 +00:00
|
|
|
value -= m_trackWidth + m_diffPairGap;
|
2023-10-16 12:12:17 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SetMaxAmplitude( KiROUND( value / pcbIUScale.mmToIU( 0.1 ) ) * pcbIUScale.mmToIU( 0.1 ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
int side = base.Side( wHandle );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( side < 0 )
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings.m_initialSide = PNS::MEANDER_SIDE_LEFT;
|
2023-10-14 12:38:25 +00:00
|
|
|
else
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings.m_initialSide = PNS::MEANDER_SIDE_RIGHT;
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( aEditPoints->Point( 3 ).IsActive() )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I wHandle = aEditPoints->Point( 2 ).GetPosition();
|
|
|
|
VECTOR2I sHandle = aEditPoints->Point( 3 ).GetPosition();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
int value = KiROUND( SEG( base.A, wHandle ).LineDistance( sHandle ) / 1.5 );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SetSpacing( KiROUND( value / pcbIUScale.mmToIU( 0.01 ) ) * pcbIUScale.mmToIU( 0.01 ) );
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
bool PCB_TUNING_PATTERN::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
VECTOR2I centerlineOffset;
|
2023-12-01 05:44:07 +00:00
|
|
|
VECTOR2I centerlineOffsetEnd;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR && m_baseLineCoupled && m_baseLineCoupled->SegmentCount() > 0 )
|
2023-12-01 05:44:07 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
centerlineOffset = ( m_baseLineCoupled->CPoint( 0 ) - m_origin ) / 2;
|
2023-12-01 05:44:07 +00:00
|
|
|
centerlineOffsetEnd = ( m_baseLineCoupled->CPoint( -1 ) - m_end ) / 2;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SEG base = m_baseLine && m_baseLine->SegmentCount() > 0 ? m_baseLine->CSegment( 0 )
|
|
|
|
: SEG( m_origin, m_end );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
base.A += centerlineOffset;
|
|
|
|
base.B += centerlineOffset;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
int amplitude = m_settings.m_maxAmplitude + KiROUND( m_trackWidth / 2.0 );
|
2023-10-16 12:12:17 +00:00
|
|
|
|
|
|
|
if( m_tuningMode == DIFF_PAIR )
|
2023-12-01 05:44:07 +00:00
|
|
|
amplitude += m_trackWidth + m_diffPairGap;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
if( m_settings.m_initialSide == -1 )
|
2023-10-16 12:12:17 +00:00
|
|
|
amplitude *= -1;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
VECTOR2I widthHandleOffset = ( base.B - base.A ).Perpendicular().Resize( amplitude );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aEditPoints->Point( 0 ).SetPosition( m_origin + centerlineOffset );
|
2023-12-01 05:44:07 +00:00
|
|
|
aEditPoints->Point( 1 ).SetPosition( m_end + centerlineOffsetEnd );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aEditPoints->Point( 2 ).SetPosition( base.A + widthHandleOffset );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
VECTOR2I spacingHandleOffset =
|
|
|
|
widthHandleOffset + ( base.B - base.A ).Resize( KiROUND( m_settings.m_spacing * 1.5 ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aEditPoints->Point( 3 ).SetPosition( base.A + spacingHandleOffset );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2024-01-24 12:40:42 +00:00
|
|
|
SHAPE_LINE_CHAIN PCB_TUNING_PATTERN::getOutline() const
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
if( m_baseLine )
|
|
|
|
{
|
2024-02-20 02:31:26 +00:00
|
|
|
int clampedMaxAmplitude = m_settings.m_maxAmplitude;
|
|
|
|
int minAllowedAmplitude = 0;
|
|
|
|
int baselineOffset = m_tuningMode == DIFF_PAIR ? ( m_diffPairGap + m_trackWidth ) / 2 : 0;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2024-02-20 02:31:26 +00:00
|
|
|
if( m_settings.m_cornerStyle == PNS::MEANDER_STYLE::MEANDER_STYLE_ROUND )
|
|
|
|
{
|
|
|
|
minAllowedAmplitude = baselineOffset + m_trackWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int correction = m_trackWidth * tan( 1 - tan( DEG2RAD( 22.5 ) ) );
|
|
|
|
minAllowedAmplitude = baselineOffset + correction;
|
|
|
|
}
|
|
|
|
|
|
|
|
clampedMaxAmplitude = std::max( clampedMaxAmplitude, minAllowedAmplitude );
|
|
|
|
|
|
|
|
if( m_settings.m_singleSided )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-12-01 05:44:07 +00:00
|
|
|
SHAPE_LINE_CHAIN clBase = *m_baseLine;
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN left, right;
|
2023-10-11 10:48:43 +00:00
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
if( m_tuningMode != DIFF_PAIR )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-02-20 02:31:26 +00:00
|
|
|
int amplitude = clampedMaxAmplitude + KiROUND( m_trackWidth / 2.0 );
|
2023-12-01 05:44:07 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN chain;
|
|
|
|
|
|
|
|
if( clBase.OffsetLine( amplitude, CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_LOW_DEF,
|
|
|
|
left, right, true ) )
|
|
|
|
{
|
|
|
|
chain.Append( m_settings.m_initialSide >= 0 ? right : left );
|
|
|
|
chain.Append( clBase.Reverse() );
|
|
|
|
chain.SetClosed( true );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
return chain;
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-12-01 05:44:07 +00:00
|
|
|
else if( m_tuningMode == DIFF_PAIR && m_baseLineCoupled )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2024-02-20 02:31:26 +00:00
|
|
|
int amplitude = clampedMaxAmplitude + m_trackWidth + KiROUND( m_diffPairGap / 2.0 );
|
2023-12-01 05:44:07 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN clCoupled = *m_baseLineCoupled;
|
|
|
|
SHAPE_LINE_CHAIN chain1, chain2;
|
|
|
|
|
|
|
|
if( clBase.OffsetLine( amplitude, CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_LOW_DEF,
|
|
|
|
left, right, true ) )
|
|
|
|
{
|
|
|
|
if( m_settings.m_initialSide >= 0 )
|
|
|
|
chain1.Append( right );
|
|
|
|
else
|
|
|
|
chain1.Append( left );
|
|
|
|
|
|
|
|
if( clBase.OffsetLine( KiROUND( m_trackWidth / 2.0 ),
|
|
|
|
CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_LOW_DEF, left,
|
|
|
|
right, true ) )
|
|
|
|
{
|
|
|
|
if( m_settings.m_initialSide >= 0 )
|
|
|
|
chain1.Append( left.Reverse() );
|
|
|
|
else
|
|
|
|
chain1.Append( right.Reverse() );
|
|
|
|
}
|
|
|
|
|
|
|
|
chain1.SetClosed( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( clCoupled.OffsetLine( amplitude, CORNER_STRATEGY::ROUND_ALL_CORNERS,
|
|
|
|
ARC_LOW_DEF, left, right, true ) )
|
|
|
|
{
|
|
|
|
if( m_settings.m_initialSide >= 0 )
|
|
|
|
chain2.Append( right );
|
|
|
|
else
|
|
|
|
chain2.Append( left );
|
|
|
|
|
|
|
|
if( clCoupled.OffsetLine( KiROUND( m_trackWidth / 2.0 ),
|
|
|
|
CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_LOW_DEF, left,
|
|
|
|
right, true ) )
|
|
|
|
{
|
|
|
|
if( m_settings.m_initialSide >= 0 )
|
|
|
|
chain2.Append( left.Reverse() );
|
|
|
|
else
|
|
|
|
chain2.Append( right.Reverse() );
|
|
|
|
}
|
|
|
|
|
|
|
|
chain2.SetClosed( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
SHAPE_POLY_SET merged;
|
|
|
|
merged.BooleanAdd( chain1, chain2, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
|
|
|
|
if( merged.OutlineCount() > 0 )
|
|
|
|
return merged.Outline( 0 );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
// Not single-sided / fallback
|
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
SHAPE_LINE_CHAIN cl = *m_baseLine;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2024-02-20 02:31:26 +00:00
|
|
|
int amplitude = 0;
|
2023-10-14 12:38:25 +00:00
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR )
|
2024-02-20 02:31:26 +00:00
|
|
|
amplitude = clampedMaxAmplitude + m_diffPairGap / 2 + KiROUND( m_trackWidth );
|
|
|
|
else
|
|
|
|
amplitude = clampedMaxAmplitude + KiROUND( m_trackWidth / 2.0 );
|
2023-12-01 05:44:07 +00:00
|
|
|
|
2024-02-20 00:58:23 +00:00
|
|
|
poly.OffsetLineChain( *m_baseLine, amplitude, CORNER_STRATEGY::ROUND_ALL_CORNERS,
|
|
|
|
ARC_LOW_DEF, false );
|
|
|
|
|
|
|
|
if( m_baseLineCoupled )
|
2023-12-01 05:44:07 +00:00
|
|
|
{
|
2024-02-20 00:58:23 +00:00
|
|
|
SHAPE_POLY_SET polyCoupled;
|
|
|
|
polyCoupled.OffsetLineChain( *m_baseLineCoupled, amplitude,
|
|
|
|
CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_LOW_DEF, false );
|
2023-12-01 05:44:07 +00:00
|
|
|
|
2024-02-20 00:58:23 +00:00
|
|
|
SHAPE_POLY_SET merged;
|
|
|
|
merged.BooleanAdd( poly, polyCoupled, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2023-12-01 05:44:07 +00:00
|
|
|
|
2024-02-20 00:58:23 +00:00
|
|
|
if( merged.OutlineCount() > 0 )
|
|
|
|
return merged.Outline( 0 );
|
|
|
|
}
|
2023-12-01 05:44:07 +00:00
|
|
|
|
|
|
|
if( poly.OutlineCount() > 0 )
|
|
|
|
return poly.Outline( 0 );
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-12-01 05:44:07 +00:00
|
|
|
return SHAPE_LINE_CHAIN();
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
void PCB_TUNING_PATTERN::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-11-23 23:25:32 +00:00
|
|
|
if( !IsSelected() && !IsNew() )
|
2023-10-14 12:38:25 +00:00
|
|
|
return;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
KIGFX::PREVIEW::DRAW_CONTEXT ctx( *aView );
|
2023-11-12 09:17:03 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
int size = KiROUND( aView->ToWorld( EDIT_POINT::POINT_SIZE ) * 0.8 );
|
2023-11-12 09:17:03 +00:00
|
|
|
size = std::max( size, pcbIUScale.mmToIU( 0.05 ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2024-01-24 12:40:42 +00:00
|
|
|
SHAPE_LINE_CHAIN chain = getOutline();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( int i = 0; i < chain.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
SEG seg = chain.Segment( i );
|
|
|
|
ctx.DrawLineDashed( seg.A, seg.B, size, size / 2, false );
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
const STRING_ANY_MAP PCB_TUNING_PATTERN::GetProperties() const
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
STRING_ANY_MAP props = PCB_GENERATOR::GetProperties();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
props.set( "tuning_mode", tuningToString( m_tuningMode ) );
|
2023-10-16 23:27:08 +00:00
|
|
|
props.set( "initial_side", sideToString( m_settings.m_initialSide ) );
|
2023-10-14 12:38:25 +00:00
|
|
|
props.set( "last_status", statusToString( m_tuningStatus ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
props.set( "end", m_end );
|
2023-10-16 23:27:08 +00:00
|
|
|
props.set( "corner_radius_percent", m_settings.m_cornerRadiusPercentage );
|
|
|
|
props.set( "single_sided", m_settings.m_singleSided );
|
|
|
|
props.set( "rounded", m_settings.m_cornerStyle == PNS::MEANDER_STYLE_ROUND );
|
|
|
|
|
|
|
|
props.set_iu( "max_amplitude", m_settings.m_maxAmplitude );
|
2023-12-17 02:32:02 +00:00
|
|
|
props.set_iu( "min_amplitude", m_settings.m_minAmplitude );
|
2023-10-16 23:27:08 +00:00
|
|
|
props.set_iu( "min_spacing", m_settings.m_spacing );
|
|
|
|
props.set_iu( "target_length_min", m_settings.m_targetLength.Min() );
|
|
|
|
props.set_iu( "target_length", m_settings.m_targetLength.Opt() );
|
|
|
|
props.set_iu( "target_length_max", m_settings.m_targetLength.Max() );
|
|
|
|
props.set_iu( "target_skew_min", m_settings.m_targetSkew.Min() );
|
|
|
|
props.set_iu( "target_skew", m_settings.m_targetSkew.Opt() );
|
|
|
|
props.set_iu( "target_skew_max", m_settings.m_targetSkew.Max() );
|
2023-10-16 12:12:17 +00:00
|
|
|
props.set_iu( "last_track_width", m_trackWidth );
|
|
|
|
props.set_iu( "last_diff_pair_gap", m_diffPairGap );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
props.set( "last_netname", m_lastNetName );
|
|
|
|
props.set( "last_tuning", m_tuningInfo );
|
2023-10-16 23:27:08 +00:00
|
|
|
props.set( "override_custom_rules", m_settings.m_overrideCustomRules );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_baseLine )
|
|
|
|
props.set( "base_line", wxAny( *m_baseLine ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_baseLineCoupled )
|
|
|
|
props.set( "base_line_coupled", wxAny( *m_baseLineCoupled ) );
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return props;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-11 10:48:43 +00:00
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
void PCB_TUNING_PATTERN::SetProperties( const STRING_ANY_MAP& aProps )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
PCB_GENERATOR::SetProperties( aProps );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxString tuningMode;
|
|
|
|
aProps.get_to( "tuning_mode", tuningMode );
|
|
|
|
m_tuningMode = tuningFromString( tuningMode.utf8_string() );
|
2023-10-11 10:48:43 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxString side;
|
|
|
|
aProps.get_to( "initial_side", side );
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings.m_initialSide = sideFromString( side.utf8_string() );
|
2023-10-11 10:48:43 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxString status;
|
|
|
|
aProps.get_to( "last_status", status );
|
|
|
|
m_tuningStatus = statusFromString( status.utf8_string() );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aProps.get_to( "end", m_end );
|
2023-10-16 23:27:08 +00:00
|
|
|
aProps.get_to( "corner_radius_percent", m_settings.m_cornerRadiusPercentage );
|
|
|
|
aProps.get_to( "single_sided", m_settings.m_singleSided );
|
|
|
|
aProps.get_to( "side", m_settings.m_initialSide );
|
|
|
|
|
|
|
|
bool rounded;
|
|
|
|
aProps.get_to( "rounded", rounded );
|
|
|
|
m_settings.m_cornerStyle = rounded ? PNS::MEANDER_STYLE_ROUND : PNS::MEANDER_STYLE_CHAMFER;
|
|
|
|
|
|
|
|
long long int val;
|
|
|
|
|
|
|
|
aProps.get_to_iu( "target_length", val );
|
|
|
|
m_settings.SetTargetLength( val );
|
|
|
|
|
|
|
|
if( aProps.get_to_iu( "target_length_min", val ) )
|
|
|
|
m_settings.m_targetLength.SetMin( val );
|
|
|
|
|
|
|
|
if( aProps.get_to_iu( "target_length_max", val ) )
|
|
|
|
m_settings.m_targetLength.SetMax( val );
|
|
|
|
|
|
|
|
int int_val;
|
|
|
|
|
|
|
|
aProps.get_to_iu( "target_skew", int_val );
|
|
|
|
m_settings.SetTargetSkew( int_val );
|
|
|
|
|
|
|
|
if( aProps.get_to_iu( "target_skew_min", int_val ) )
|
|
|
|
m_settings.m_targetSkew.SetMin( int_val );
|
|
|
|
|
|
|
|
if( aProps.get_to_iu( "target_skew_max", int_val ) )
|
|
|
|
m_settings.m_targetSkew.SetMax( int_val );
|
|
|
|
|
|
|
|
aProps.get_to_iu( "max_amplitude", m_settings.m_maxAmplitude );
|
2023-12-17 02:32:02 +00:00
|
|
|
aProps.get_to_iu( "min_amplitude", m_settings.m_minAmplitude );
|
2023-10-16 23:27:08 +00:00
|
|
|
aProps.get_to_iu( "min_spacing", m_settings.m_spacing );
|
2023-10-16 12:12:17 +00:00
|
|
|
aProps.get_to_iu( "last_track_width", m_trackWidth );
|
|
|
|
aProps.get_to_iu( "last_diff_pair_gap", m_diffPairGap );
|
2023-10-16 23:27:08 +00:00
|
|
|
aProps.get_to( "override_custom_rules", m_settings.m_overrideCustomRules );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aProps.get_to( "last_netname", m_lastNetName );
|
|
|
|
aProps.get_to( "last_tuning", m_tuningInfo );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( auto baseLine = aProps.get_opt<SHAPE_LINE_CHAIN>( "base_line" ) )
|
|
|
|
m_baseLine = *baseLine;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( auto baseLineCoupled = aProps.get_opt<SHAPE_LINE_CHAIN>( "base_line_coupled" ) )
|
|
|
|
m_baseLineCoupled = *baseLineCoupled;
|
|
|
|
}
|
2023-10-10 10:55:57 +00:00
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
void PCB_TUNING_PATTERN::ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-10-16 23:27:08 +00:00
|
|
|
PNS::MEANDER_SETTINGS settings = m_settings;
|
2023-10-14 12:38:25 +00:00
|
|
|
DRC_CONSTRAINT constraint;
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !m_items.empty() )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* startItem = *m_items.begin();
|
|
|
|
std::shared_ptr<DRC_ENGINE>& drcEngine = GetBoard()->GetDesignSettings().m_DRCEngine;
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
constraint = drcEngine->EvalRules( LENGTH_CONSTRAINT, startItem, nullptr, GetLayer() );
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !constraint.IsNull() && !settings.m_overrideCustomRules )
|
2023-10-16 23:27:08 +00:00
|
|
|
settings.SetTargetLength( constraint.GetValue() );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-12-11 14:47:32 +00:00
|
|
|
DIALOG_TUNING_PATTERN_PROPERTIES dlg( aEditFrame, settings, GetPNSMode(), constraint );
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
BOARD_COMMIT commit( aEditFrame );
|
|
|
|
commit.Modify( this );
|
2023-10-16 23:27:08 +00:00
|
|
|
m_settings = settings;
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-12-15 21:04:33 +00:00
|
|
|
GENERATOR_TOOL* generatorTool = aEditFrame->GetToolManager()->GetTool<GENERATOR_TOOL>();
|
2023-12-16 16:11:45 +00:00
|
|
|
EditStart( generatorTool, GetBoard(), &commit );
|
|
|
|
Update( generatorTool, GetBoard(), &commit );
|
|
|
|
EditPush( generatorTool, GetBoard(), &commit );
|
2023-12-15 21:04:33 +00:00
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
std::vector<EDA_ITEM*> PCB_TUNING_PATTERN::GetPreviewItems( GENERATOR_TOOL* aTool,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame,
|
2023-12-06 13:08:05 +00:00
|
|
|
bool aStatusItemsOnly )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
2023-12-02 10:32:45 +00:00
|
|
|
std::vector<EDA_ITEM*> previewItems;
|
|
|
|
KIGFX::VIEW* view = aFrame->GetCanvas()->GetView();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
if( auto* placer = dynamic_cast<PNS::MEANDER_PLACER_BASE*>( aTool->Router()->Placer() ) )
|
2023-10-17 12:03:38 +00:00
|
|
|
{
|
2023-12-06 13:08:05 +00:00
|
|
|
if( !aStatusItemsOnly )
|
2023-12-02 10:32:45 +00:00
|
|
|
{
|
|
|
|
PNS::ITEM_SET items = placer->TunedPath();
|
|
|
|
|
|
|
|
for( PNS::ITEM* item : items )
|
2023-12-08 16:01:27 +00:00
|
|
|
previewItems.push_back( new ROUTER_PREVIEW_ITEM( item, view, PNS_HOVER_ITEM ) );
|
2023-12-02 10:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TUNING_STATUS_VIEW_ITEM* statusItem = new TUNING_STATUS_VIEW_ITEM( aFrame );
|
|
|
|
|
2024-02-08 15:55:25 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR_SKEW )
|
2023-12-02 10:32:45 +00:00
|
|
|
{
|
|
|
|
statusItem->SetMinMax( m_settings.m_targetSkew.Min(), m_settings.m_targetSkew.Max() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-08 16:34:17 +00:00
|
|
|
if( m_settings.m_targetLength.Opt() == PNS::MEANDER_SETTINGS::LENGTH_UNCONSTRAINED )
|
2024-02-08 15:55:25 +00:00
|
|
|
{
|
|
|
|
statusItem->ClearMinMax();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
statusItem->SetMinMax( (double) m_settings.m_targetLength.Min(),
|
|
|
|
(double) m_settings.m_targetLength.Max() );
|
|
|
|
}
|
2023-12-02 10:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_tuningMode == DIFF_PAIR_SKEW )
|
2023-12-03 13:20:47 +00:00
|
|
|
statusItem->SetCurrent( (double) placer->TuningResult(), _( "current skew" ) );
|
2023-12-02 10:32:45 +00:00
|
|
|
else
|
2023-12-03 13:20:47 +00:00
|
|
|
statusItem->SetCurrent( (double) placer->TuningResult(), _( "current length" ) );
|
2023-12-02 10:32:45 +00:00
|
|
|
|
|
|
|
statusItem->SetPosition( aFrame->GetToolManager()->GetMousePosition() );
|
|
|
|
previewItems.push_back( statusItem );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-11-23 18:41:59 +00:00
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
return previewItems;
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-09 20:48:34 +00:00
|
|
|
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
void PCB_TUNING_PATTERN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
2023-10-15 13:13:32 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
NETINFO_ITEM* primaryNet = nullptr;
|
|
|
|
NETINFO_ITEM* coupledNet = nullptr;
|
|
|
|
PCB_TRACK* primaryItem = nullptr;
|
|
|
|
PCB_TRACK* coupledItem = nullptr;
|
|
|
|
NETCLASS* netclass = nullptr;
|
|
|
|
int width = 0;
|
|
|
|
bool mixedWidth = false;
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Type" ), GetFriendlyName() );
|
|
|
|
|
|
|
|
for( BOARD_ITEM* member : GetItems() )
|
|
|
|
{
|
|
|
|
if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( member ) )
|
|
|
|
{
|
|
|
|
if( !primaryNet )
|
|
|
|
{
|
|
|
|
primaryItem = track;
|
|
|
|
primaryNet = track->GetNet();
|
|
|
|
}
|
|
|
|
else if( !coupledNet && track->GetNet() != primaryNet )
|
|
|
|
{
|
|
|
|
coupledItem = track;
|
|
|
|
coupledNet = track->GetNet();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !netclass )
|
|
|
|
netclass = track->GetEffectiveNetClass();
|
|
|
|
|
|
|
|
if( !width )
|
|
|
|
width = track->GetWidth();
|
|
|
|
else if( width != track->GetWidth() )
|
|
|
|
mixedWidth = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( coupledNet )
|
|
|
|
{
|
|
|
|
aList.emplace_back( _( "Nets" ), UnescapeString( primaryNet->GetNetname() )
|
|
|
|
+ wxS( ", " )
|
|
|
|
+ UnescapeString( coupledNet->GetNetname() ) );
|
|
|
|
}
|
|
|
|
else if( primaryNet )
|
|
|
|
{
|
|
|
|
aList.emplace_back( _( "Net" ), UnescapeString( primaryNet->GetNetname() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( netclass )
|
|
|
|
aList.emplace_back( _( "Resolved Netclass" ), UnescapeString( netclass->GetName() ) );
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Layer" ), layerMaskDescribe() );
|
|
|
|
|
|
|
|
if( width && !mixedWidth )
|
|
|
|
aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( width ) );
|
|
|
|
|
|
|
|
BOARD* board = GetBoard();
|
|
|
|
std::shared_ptr<DRC_ENGINE>& drcEngine = board->GetDesignSettings().m_DRCEngine;
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
|
|
|
|
// Display full track length (in Pcbnew)
|
|
|
|
if( board && primaryItem && primaryItem->GetNetCode() > 0 )
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
double trackLen;
|
|
|
|
double lenPadToDie;
|
|
|
|
|
|
|
|
std::tie( count, trackLen, lenPadToDie ) = board->GetTrackLength( *primaryItem );
|
|
|
|
|
|
|
|
if( coupledItem && coupledItem->GetNetCode() > 0 )
|
|
|
|
{
|
|
|
|
double coupledLen;
|
|
|
|
std::tie( count, coupledLen, lenPadToDie ) = board->GetTrackLength( *coupledItem );
|
|
|
|
|
|
|
|
aList.emplace_back( _( "Routed Lengths" ), aFrame->MessageTextFromValue( trackLen )
|
|
|
|
+ wxS( ", " )
|
|
|
|
+ aFrame->MessageTextFromValue( coupledLen ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aList.emplace_back( _( "Routed Length" ), aFrame->MessageTextFromValue( trackLen ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lenPadToDie != 0 )
|
|
|
|
{
|
|
|
|
msg = aFrame->MessageTextFromValue( lenPadToDie );
|
|
|
|
aList.emplace_back( _( "Pad To Die Length" ), msg );
|
|
|
|
|
|
|
|
msg = aFrame->MessageTextFromValue( trackLen + lenPadToDie );
|
|
|
|
aList.emplace_back( _( "Full Length" ), msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_tuningMode == DIFF_PAIR_SKEW )
|
|
|
|
{
|
|
|
|
constraint = drcEngine->EvalRules( SKEW_CONSTRAINT, primaryItem, coupledItem, m_layer );
|
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
if( constraint.IsNull() || m_settings.m_overrideCustomRules )
|
2023-10-15 13:13:32 +00:00
|
|
|
{
|
2023-10-16 23:27:08 +00:00
|
|
|
msg = aFrame->MessageTextFromValue( m_settings.m_targetSkew.Opt() );
|
2023-10-15 13:13:32 +00:00
|
|
|
|
|
|
|
aList.emplace_back( wxString::Format( _( "Target Skew: %s" ), msg ),
|
|
|
|
wxString::Format( _( "(from tuning pattern properties)" ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-15 21:08:27 +00:00
|
|
|
msg = aFrame->MessageTextFromMinOptMax( constraint.GetValue() );
|
2023-10-15 13:13:32 +00:00
|
|
|
|
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
{
|
2023-10-15 21:08:27 +00:00
|
|
|
aList.emplace_back( wxString::Format( _( "Skew Constraints: %s" ), msg ),
|
2023-10-15 13:13:32 +00:00
|
|
|
wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
constraint = drcEngine->EvalRules( LENGTH_CONSTRAINT, primaryItem, coupledItem, m_layer );
|
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
if( constraint.IsNull() || m_settings.m_overrideCustomRules )
|
2023-10-15 13:13:32 +00:00
|
|
|
{
|
2023-10-16 23:27:08 +00:00
|
|
|
msg = aFrame->MessageTextFromValue( (double) m_settings.m_targetLength.Opt() );
|
2023-10-15 13:13:32 +00:00
|
|
|
|
|
|
|
aList.emplace_back( wxString::Format( _( "Target Length: %s" ), msg ),
|
|
|
|
wxString::Format( _( "(from tuning pattern properties)" ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-15 21:08:27 +00:00
|
|
|
msg = aFrame->MessageTextFromMinOptMax( constraint.GetValue() );
|
2023-10-15 13:13:32 +00:00
|
|
|
|
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
{
|
2023-10-15 21:08:27 +00:00
|
|
|
aList.emplace_back( wxString::Format( _( "Length Constraints: %s" ), msg ),
|
2023-10-15 13:13:32 +00:00
|
|
|
wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
const wxString PCB_TUNING_PATTERN::DISPLAY_NAME = _HKI( "Tuning Pattern" );
|
|
|
|
const wxString PCB_TUNING_PATTERN::GENERATOR_TYPE = wxS( "tuning_pattern" );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-11 15:02:07 +00:00
|
|
|
using SCOPED_DRAW_MODE = SCOPED_SET_RESET<DRAWING_TOOL::MODE>;
|
|
|
|
|
|
|
|
|
2023-10-09 14:22:16 +00:00
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
int DRAWING_TOOL::PlaceTuningPattern( const TOOL_EVENT& aEvent )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-11 13:43:54 +00:00
|
|
|
if( m_inDrawingTool )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inDrawingTool );
|
2023-10-09 14:22:16 +00:00
|
|
|
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
m_frame->PushTool( aEvent );
|
2023-10-09 14:22:16 +00:00
|
|
|
Activate();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-12-11 14:47:32 +00:00
|
|
|
BOARD* board = m_frame->GetBoard();
|
|
|
|
std::shared_ptr<DRC_ENGINE>& drcEngine = board->GetDesignSettings().m_DRCEngine;
|
|
|
|
GENERATOR_TOOL* generatorTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
|
|
|
|
PNS::ROUTER* router = generatorTool->Router();
|
|
|
|
LENGTH_TUNING_MODE mode = fromPNSMode( aEvent.Parameter<PNS::ROUTER_MODE>() );
|
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
|
2023-10-15 16:02:15 +00:00
|
|
|
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TUNING );
|
2023-10-11 13:43:54 +00:00
|
|
|
|
2023-10-09 14:22:16 +00:00
|
|
|
m_pickerItem = nullptr;
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern = nullptr;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-11 13:09:53 +00:00
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
|
|
|
m_preview.Clear();
|
|
|
|
m_view->Add( &m_preview );
|
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
};
|
|
|
|
|
2023-11-23 18:41:59 +00:00
|
|
|
auto updateHoverStatus =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
std::unique_ptr<PCB_TUNING_PATTERN> dummyPattern;
|
|
|
|
|
|
|
|
if( m_pickerItem )
|
|
|
|
{
|
|
|
|
dummyPattern.reset( PCB_TUNING_PATTERN::CreateNew( generatorTool, m_frame,
|
2023-12-08 17:00:55 +00:00
|
|
|
m_pickerItem, mode ) );
|
2023-12-20 15:27:29 +00:00
|
|
|
dummyPattern->SetPosition( m_pickerItem->GetFocusPosition() );
|
|
|
|
dummyPattern->SetEnd( m_pickerItem->GetFocusPosition() );
|
2023-11-23 18:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( dummyPattern )
|
|
|
|
{
|
2023-12-16 16:11:45 +00:00
|
|
|
dummyPattern->EditStart( generatorTool, m_board, nullptr );
|
|
|
|
dummyPattern->Update( generatorTool, m_board, nullptr );
|
2023-11-23 18:41:59 +00:00
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
m_preview.FreeItems();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : dummyPattern->GetPreviewItems( generatorTool, m_frame ) )
|
|
|
|
m_preview.Add( item );
|
2023-11-26 18:18:13 +00:00
|
|
|
|
|
|
|
generatorTool->Router()->StopRouting();
|
2023-12-02 10:32:45 +00:00
|
|
|
|
|
|
|
m_view->Update( &m_preview );
|
2023-11-23 18:41:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-02 10:32:45 +00:00
|
|
|
m_preview.FreeItems();
|
|
|
|
m_view->Update( &m_preview );
|
2023-11-23 18:41:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
auto updateTuningPattern =
|
2023-10-11 14:50:15 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2023-10-15 16:02:15 +00:00
|
|
|
if( m_tuningPattern && m_tuningPattern->GetPosition() != m_tuningPattern->GetEnd() )
|
2023-10-11 14:50:15 +00:00
|
|
|
{
|
2023-12-16 16:11:45 +00:00
|
|
|
m_tuningPattern->EditStart( generatorTool, m_board, nullptr );
|
|
|
|
m_tuningPattern->Update( generatorTool, m_board, nullptr );
|
2023-10-11 14:50:15 +00:00
|
|
|
|
2023-12-03 14:23:57 +00:00
|
|
|
m_preview.FreeItems();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : m_tuningPattern->GetPreviewItems( generatorTool, m_frame,
|
|
|
|
true ) )
|
|
|
|
{
|
|
|
|
m_preview.Add( item );
|
|
|
|
}
|
|
|
|
|
2023-10-11 14:50:15 +00:00
|
|
|
m_view->Update( &m_preview );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
|
|
|
{
|
|
|
|
setCursor();
|
|
|
|
VECTOR2D cursorPos = controls->GetMousePosition();
|
|
|
|
|
2024-01-28 21:10:46 +00:00
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate()
|
|
|
|
|| ( m_tuningPattern && evt->IsAction( &ACTIONS::undo ) ) )
|
2023-10-11 13:43:54 +00:00
|
|
|
{
|
2023-10-15 16:02:15 +00:00
|
|
|
if( m_tuningPattern )
|
2023-10-09 14:22:16 +00:00
|
|
|
{
|
2023-10-18 13:50:48 +00:00
|
|
|
// First click already made; clean up tuning pattern preview
|
2023-12-16 16:11:45 +00:00
|
|
|
m_tuningPattern->EditRevert( generatorTool, m_board, nullptr );
|
2023-10-09 20:46:24 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
delete m_tuningPattern;
|
|
|
|
m_tuningPattern = nullptr;
|
2023-10-11 13:43:54 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
2023-10-15 16:02:15 +00:00
|
|
|
if( !m_tuningPattern )
|
2023-10-09 14:22:16 +00:00
|
|
|
{
|
2023-10-11 13:43:54 +00:00
|
|
|
// First click not yet made; we're in highlight-net-under-cursor mode
|
2023-10-09 14:22:16 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
GENERAL_COLLECTOR collector;
|
2023-10-09 14:22:16 +00:00
|
|
|
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
2023-11-28 17:40:44 +00:00
|
|
|
|
|
|
|
if( m_frame->GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL )
|
|
|
|
guide.SetIncludeSecondary( false );
|
|
|
|
else
|
|
|
|
guide.SetIncludeSecondary( true );
|
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
collector.Collect( board, { PCB_TRACE_T, PCB_ARC_T }, cursorPos, guide );
|
2023-10-09 14:22:16 +00:00
|
|
|
|
|
|
|
if( collector.GetCount() > 1 )
|
2023-10-11 13:43:54 +00:00
|
|
|
selectionTool->GuessSelectionCandidates( collector, cursorPos );
|
2023-10-09 14:22:16 +00:00
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
if( collector.GetCount() == 1 )
|
|
|
|
m_pickerItem = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] );
|
2023-10-09 14:22:16 +00:00
|
|
|
else
|
2023-12-02 10:32:45 +00:00
|
|
|
m_pickerItem = nullptr;
|
2023-11-23 18:41:59 +00:00
|
|
|
|
|
|
|
updateHoverStatus();
|
2023-10-11 13:43:54 +00:00
|
|
|
}
|
|
|
|
else
|
2023-10-09 14:22:16 +00:00
|
|
|
{
|
2023-10-18 13:50:48 +00:00
|
|
|
// First click already made; we're in preview-tuning-pattern mode
|
2023-10-11 13:43:54 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->SetEnd( cursorPos );
|
2023-10-18 13:50:48 +00:00
|
|
|
updateTuningPattern();
|
2023-10-11 13:43:54 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 16:10:48 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
2023-10-15 16:02:15 +00:00
|
|
|
if( m_pickerItem && !m_tuningPattern )
|
2023-10-11 16:10:48 +00:00
|
|
|
{
|
2023-10-18 13:50:48 +00:00
|
|
|
// First click; create a tuning pattern
|
2023-10-11 16:10:48 +00:00
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
m_preview.FreeItems();
|
2023-10-11 16:10:48 +00:00
|
|
|
|
|
|
|
m_frame->SetActiveLayer( m_pickerItem->GetLayer() );
|
2023-10-18 13:50:48 +00:00
|
|
|
m_tuningPattern = PCB_TUNING_PATTERN::CreateNew( generatorTool, m_frame,
|
|
|
|
m_pickerItem, mode );
|
2023-10-11 16:10:48 +00:00
|
|
|
|
2023-12-08 17:00:55 +00:00
|
|
|
int dummyDist;
|
|
|
|
int dummyClearance = std::numeric_limits<int>::max() / 2;
|
|
|
|
VECTOR2I closestPt;
|
2023-10-11 16:10:48 +00:00
|
|
|
|
2023-12-08 17:00:55 +00:00
|
|
|
// With an artificially-large clearance this can't *not* collide, but the
|
|
|
|
// if stmt keeps Coverity happy....
|
|
|
|
if( m_pickerItem->GetEffectiveShape()->Collide( cursorPos, dummyClearance,
|
|
|
|
&dummyDist, &closestPt ) )
|
|
|
|
{
|
|
|
|
m_tuningPattern->SetPosition( closestPt );
|
|
|
|
m_tuningPattern->SetEnd( closestPt );
|
2023-10-20 15:02:03 +00:00
|
|
|
}
|
2023-12-08 17:00:55 +00:00
|
|
|
|
|
|
|
m_preview.Add( m_tuningPattern->Clone() );
|
2023-10-11 16:10:48 +00:00
|
|
|
}
|
2023-10-15 16:02:15 +00:00
|
|
|
else if( m_pickerItem && m_tuningPattern )
|
2023-10-11 16:10:48 +00:00
|
|
|
{
|
|
|
|
// Second click; we're done
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
|
2023-12-16 16:11:45 +00:00
|
|
|
m_tuningPattern->EditStart( generatorTool, m_board, &commit );
|
|
|
|
m_tuningPattern->Update( generatorTool, m_board, &commit );
|
|
|
|
m_tuningPattern->EditPush( generatorTool, m_board, &commit, _( "Tune" ) );
|
2023-10-11 16:10:48 +00:00
|
|
|
|
2023-10-19 00:31:01 +00:00
|
|
|
for( BOARD_ITEM* item : m_tuningPattern->GetItems() )
|
|
|
|
item->SetSelected();
|
|
|
|
|
2023-10-11 16:10:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-10-11 13:43:54 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
PCB_SELECTION dummy;
|
|
|
|
m_menu.ShowContextMenu( dummy );
|
|
|
|
}
|
2023-10-11 14:50:15 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::spacingIncrease )
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::spacingDecrease ) )
|
|
|
|
{
|
2023-10-15 16:02:15 +00:00
|
|
|
if( m_tuningPattern )
|
2023-10-11 14:50:15 +00:00
|
|
|
{
|
|
|
|
auto* placer = static_cast<PNS::MEANDER_PLACER_BASE*>( router->Placer() );
|
|
|
|
|
|
|
|
placer->SpacingStep( evt->IsAction( &PCB_ACTIONS::spacingIncrease ) ? 1 : -1 );
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->SetSpacing( placer->MeanderSettings().m_spacing );
|
2023-10-18 13:50:48 +00:00
|
|
|
updateTuningPattern();
|
2023-10-11 14:50:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::amplIncrease )
|
|
|
|
|| evt->IsAction( &PCB_ACTIONS::amplDecrease ) )
|
|
|
|
{
|
2023-10-15 16:02:15 +00:00
|
|
|
if( m_tuningPattern )
|
2023-10-11 14:50:15 +00:00
|
|
|
{
|
|
|
|
auto* placer = static_cast<PNS::MEANDER_PLACER_BASE*>( router->Placer() );
|
|
|
|
|
|
|
|
placer->AmplitudeStep( evt->IsAction( &PCB_ACTIONS::amplIncrease ) ? 1 : -1 );
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->SetMaxAmplitude( placer->MeanderSettings().m_maxAmplitude );
|
2023-10-18 13:50:48 +00:00
|
|
|
updateTuningPattern();
|
2023-12-11 14:47:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::properties ) )
|
|
|
|
{
|
|
|
|
if( m_tuningPattern )
|
|
|
|
{
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
|
|
|
|
if( !m_tuningPattern->GetItems().empty() )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* startItem = *m_tuningPattern->GetItems().begin();
|
|
|
|
|
|
|
|
constraint = drcEngine->EvalRules( LENGTH_CONSTRAINT, startItem, nullptr,
|
|
|
|
startItem->GetLayer() );
|
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_TUNING_PATTERN_PROPERTIES dlg( m_frame, m_tuningPattern->GetSettings(),
|
|
|
|
m_tuningPattern->GetPNSMode(), constraint );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
updateTuningPattern();
|
2023-10-11 14:50:15 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 13:43:54 +00:00
|
|
|
// TODO: It'd be nice to be able to say "don't allow any non-trivial editing actions",
|
|
|
|
// but we don't at present have that, so we just knock out some of the egregious ones.
|
|
|
|
else if( ZONE_FILLER_TOOL::IsZoneFillAction( evt ) )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evt->SetPassEvent();
|
|
|
|
}
|
2023-10-09 14:22:16 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
controls->CaptureCursor( m_tuningPattern != nullptr );
|
|
|
|
controls->SetAutoPan( m_tuningPattern != nullptr );
|
2023-10-11 13:43:54 +00:00
|
|
|
}
|
2023-10-09 20:46:24 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
controls->CaptureCursor( false );
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
controls->ShowCursor( false );
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
m_preview.FreeItems();
|
2023-10-11 13:43:54 +00:00
|
|
|
m_view->Remove( &m_preview );
|
2023-10-11 13:09:53 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2023-10-09 14:22:16 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
if( m_tuningPattern )
|
|
|
|
selectionTool->AddItemToSel( m_tuningPattern );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
m_frame->PopTool( aEvent );
|
2023-10-07 03:54:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
static struct PCB_TUNING_PATTERN_DESC
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-18 13:50:48 +00:00
|
|
|
PCB_TUNING_PATTERN_DESC()
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
|
|
|
ENUM_MAP<LENGTH_TUNING_MODE>::Instance()
|
|
|
|
.Map( LENGTH_TUNING_MODE::SINGLE, _HKI( "Single track" ) )
|
2023-10-15 21:08:27 +00:00
|
|
|
.Map( LENGTH_TUNING_MODE::DIFF_PAIR, _HKI( "Differential pair" ) )
|
|
|
|
.Map( LENGTH_TUNING_MODE::DIFF_PAIR_SKEW, _HKI( "Diff pair skew" ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
ENUM_MAP<PNS::MEANDER_SIDE>::Instance()
|
|
|
|
.Map( PNS::MEANDER_SIDE_LEFT, _HKI( "Left" ) )
|
|
|
|
.Map( PNS::MEANDER_SIDE_RIGHT, _HKI( "Right" ) )
|
|
|
|
.Map( PNS::MEANDER_SIDE_DEFAULT, _HKI( "Default" ) );
|
|
|
|
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2023-10-18 13:50:48 +00:00
|
|
|
REGISTER_TYPE( PCB_TUNING_PATTERN );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_TUNING_PATTERN, PCB_GENERATOR> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_TUNING_PATTERN, BOARD_ITEM> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_TUNING_PATTERN ), TYPE_HASH( PCB_GENERATOR ) );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_TUNING_PATTERN ), TYPE_HASH( BOARD_ITEM ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
const wxString groupTab = _HKI( "Pattern Properties" );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
|
|
|
|
_HKI( "End X" ), &PCB_TUNING_PATTERN::SetEndX,
|
|
|
|
&PCB_TUNING_PATTERN::GetEndX, PROPERTY_DISPLAY::PT_SIZE,
|
2023-10-07 03:54:14 +00:00
|
|
|
ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
|
|
|
|
_HKI( "End Y" ), &PCB_TUNING_PATTERN::SetEndY,
|
|
|
|
&PCB_TUNING_PATTERN::GetEndY, PROPERTY_DISPLAY::PT_SIZE,
|
2023-10-07 03:54:14 +00:00
|
|
|
ORIGIN_TRANSFORMS::ABS_Y_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<PCB_TUNING_PATTERN, LENGTH_TUNING_MODE>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Tuning Mode" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
NO_SETTER( PCB_TUNING_PATTERN, LENGTH_TUNING_MODE ),
|
|
|
|
&PCB_TUNING_PATTERN::GetTuningMode ),
|
2023-10-07 03:54:14 +00:00
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Min Amplitude" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::SetMinAmplitude,
|
|
|
|
&PCB_TUNING_PATTERN::GetMinAmplitude,
|
2023-10-07 03:54:14 +00:00
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Max Amplitude" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::SetMaxAmplitude,
|
|
|
|
&PCB_TUNING_PATTERN::GetMaxAmplitude,
|
2023-10-07 03:54:14 +00:00
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<PCB_TUNING_PATTERN, PNS::MEANDER_SIDE>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Initial Side" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::SetInitialSide,
|
|
|
|
&PCB_TUNING_PATTERN::GetInitialSide ),
|
2023-10-07 03:54:14 +00:00
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Min Spacing" ), &PCB_TUNING_PATTERN::SetSpacing,
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::GetSpacing, PROPERTY_DISPLAY::PT_SIZE,
|
2023-10-07 03:54:14 +00:00
|
|
|
ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Corner Radius %" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::SetCornerRadiusPercentage,
|
|
|
|
&PCB_TUNING_PATTERN::GetCornerRadiusPercentage,
|
2023-10-07 03:54:14 +00:00
|
|
|
PROPERTY_DISPLAY::PT_DEFAULT, ORIGIN_TRANSFORMS::NOT_A_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-17 12:30:40 +00:00
|
|
|
auto isSkew =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
2023-10-18 13:50:48 +00:00
|
|
|
if( PCB_TUNING_PATTERN* pattern = dynamic_cast<PCB_TUNING_PATTERN*>( aItem ) )
|
2023-10-17 12:30:40 +00:00
|
|
|
return pattern->GetTuningMode() == DIFF_PAIR_SKEW;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto notIsSkew =
|
|
|
|
[&]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
return !isSkew( aItem );
|
|
|
|
};
|
|
|
|
|
2024-02-08 18:14:20 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, std::optional<int>>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Target Length" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::SetTargetLength,
|
|
|
|
&PCB_TUNING_PATTERN::GetTargetLength,
|
2023-10-07 03:54:14 +00:00
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
2023-10-17 12:30:40 +00:00
|
|
|
groupTab )
|
|
|
|
.SetAvailableFunc( notIsSkew );
|
|
|
|
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2024-02-08 23:56:05 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Target Skew" ), &PCB_TUNING_PATTERN::SetTargetSkew,
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::GetTargetSkew,
|
2023-10-07 03:54:14 +00:00
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
2023-10-17 12:30:40 +00:00
|
|
|
groupTab )
|
|
|
|
.SetAvailableFunc( isSkew );
|
|
|
|
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, bool>(
|
2023-11-23 20:32:29 +00:00
|
|
|
_HKI( "Override Custom Rules" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::SetOverrideCustomRules,
|
|
|
|
&PCB_TUNING_PATTERN::GetOverrideCustomRules ),
|
2023-10-11 10:48:43 +00:00
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, bool>(
|
2023-10-07 03:54:14 +00:00
|
|
|
_HKI( "Single-sided" ),
|
2023-10-18 13:50:48 +00:00
|
|
|
&PCB_TUNING_PATTERN::SetSingleSided,
|
|
|
|
&PCB_TUNING_PATTERN::IsSingleSided ),
|
2023-10-07 03:54:14 +00:00
|
|
|
groupTab );
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, bool>(
|
|
|
|
_HKI( "Rounded" ), &PCB_TUNING_PATTERN::SetRounded,
|
|
|
|
&PCB_TUNING_PATTERN::IsRounded ),
|
2023-10-07 03:54:14 +00:00
|
|
|
groupTab );
|
|
|
|
}
|
2023-10-18 13:50:48 +00:00
|
|
|
} _PCB_TUNING_PATTERN_DESC;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
ENUM_TO_WXANY( LENGTH_TUNING_MODE )
|
|
|
|
ENUM_TO_WXANY( PNS::MEANDER_SIDE )
|
|
|
|
|
2023-10-18 13:50:48 +00:00
|
|
|
static GENERATORS_MGR::REGISTER<PCB_TUNING_PATTERN> registerMe;
|
|
|
|
|
|
|
|
// Also register under the 7.99 name
|
|
|
|
template <typename T>
|
|
|
|
struct REGISTER_LEGACY_TUNING_PATTERN
|
|
|
|
{
|
|
|
|
REGISTER_LEGACY_TUNING_PATTERN()
|
|
|
|
{
|
|
|
|
GENERATORS_MGR::Instance().Register( wxS( "meanders" ), T::DISPLAY_NAME,
|
|
|
|
[]()
|
|
|
|
{
|
|
|
|
return new T;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static REGISTER_LEGACY_TUNING_PATTERN<PCB_TUNING_PATTERN> registerMeToo;
|