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>
|
|
|
|
#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-15 16:02:15 +00:00
|
|
|
#include <status_popup.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>
|
|
|
|
#include <view/view.h>
|
|
|
|
|
|
|
|
#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>
|
|
|
|
#include <router/pns_topology.h>
|
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
class PCB_GENERATOR_MEANDERS : public PCB_GENERATOR
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const wxString GENERATOR_TYPE;
|
|
|
|
static const wxString DISPLAY_NAME;
|
|
|
|
|
|
|
|
PCB_GENERATOR_MEANDERS( BOARD_ITEM* aParent = nullptr, PCB_LAYER_ID aLayer = F_Cu,
|
|
|
|
LENGTH_TUNING_MODE aMode = LENGTH_TUNING_MODE::SINGLE );
|
|
|
|
|
|
|
|
wxString GetGeneratorType() const override { return wxS( "meanders" ); }
|
|
|
|
|
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-14 12:38:25 +00:00
|
|
|
static PCB_GENERATOR_MEANDERS* CreateNew( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_CONNECTED_ITEM* aStartItem,
|
|
|
|
LENGTH_TUNING_MODE aMode );
|
|
|
|
|
|
|
|
void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_COMMIT* aCommit ) override;
|
|
|
|
|
|
|
|
bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_COMMIT* aCommit ) override;
|
|
|
|
|
|
|
|
void EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_COMMIT* aCommit, const wxString& aCommitMsg = wxEmptyString,
|
|
|
|
int aCommitFlags = 0 ) override;
|
|
|
|
|
|
|
|
void EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_COMMIT* aCommit ) override;
|
|
|
|
|
|
|
|
void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_COMMIT* aCommit ) override;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I GetBoundingBox() const override { return getRectShape().BBox(); }
|
|
|
|
|
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override
|
|
|
|
{
|
|
|
|
aCount = 0;
|
|
|
|
aLayers[aCount++] = LAYER_ANCHOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override
|
|
|
|
{
|
|
|
|
return getRectShape().Collide( aPosition, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const override
|
|
|
|
{
|
|
|
|
return GetBoundingBox().Intersects( aRect );
|
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I ViewBBox() const override { return GetBoundingBox(); }
|
|
|
|
|
|
|
|
EDA_ITEM* Clone() const override { return new PCB_GENERATOR_MEANDERS( *this ); }
|
|
|
|
|
|
|
|
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; }
|
|
|
|
void SetTuningMode( LENGTH_TUNING_MODE aValue ) { m_tuningMode = aValue; }
|
|
|
|
|
|
|
|
int GetMinAmplitude() const { return m_minAmplitude; }
|
|
|
|
void SetMinAmplitude( int aValue ) { m_minAmplitude = aValue; }
|
|
|
|
|
|
|
|
int GetMaxAmplitude() const { return m_maxAmplitude; }
|
|
|
|
void SetMaxAmplitude( int aValue ) { m_maxAmplitude = aValue; }
|
|
|
|
|
|
|
|
PNS::MEANDER_SIDE GetInitialSide() const { return m_initialSide; }
|
|
|
|
void SetInitialSide( PNS::MEANDER_SIDE aValue ) { m_initialSide = aValue; }
|
|
|
|
|
|
|
|
int GetSpacing() const { return m_spacing; }
|
|
|
|
void SetSpacing( int aValue ) { m_spacing = aValue; }
|
|
|
|
|
|
|
|
long long int GetTargetLength() const { return m_targetLength; }
|
|
|
|
void SetTargetLength( long long int aValue ) { m_targetLength = aValue; }
|
|
|
|
|
|
|
|
int GetTargetSkew() const { return m_targetSkew; }
|
|
|
|
void SetTargetSkew( int aValue ) { m_targetSkew = aValue; }
|
|
|
|
|
|
|
|
bool GetOverrideCustomRules() const { return m_overrideCustomRules; }
|
|
|
|
void SetOverrideCustomRules( bool aOverride ) { m_overrideCustomRules = aOverride; }
|
|
|
|
|
|
|
|
int GetCornerRadiusPercentage() const { return m_cornerRadiusPercentage; }
|
|
|
|
void SetCornerRadiusPercentage( int aValue ) { m_cornerRadiusPercentage = aValue; }
|
|
|
|
|
|
|
|
bool IsSingleSided() const { return m_singleSide; }
|
|
|
|
void SetSingleSided( bool aValue ) { m_singleSide = aValue; }
|
|
|
|
|
|
|
|
bool IsRounded() const { return m_rounded; }
|
|
|
|
void SetRounded( bool aValue ) { m_rounded = aValue; }
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
void UpdateStatus( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
STATUS_TEXT_POPUP* aPopup ) override;
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
std::swap( *this, *static_cast<PCB_GENERATOR_MEANDERS*>( aImage ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
PNS::MEANDER_SETTINGS toMeanderSettings();
|
|
|
|
void fromMeanderSettings( const PNS::MEANDER_SETTINGS& aSettings );
|
|
|
|
|
|
|
|
PNS::ROUTER_MODE toPNSMode();
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
void removeToBaseline( PNS::ROUTER* aRouter, int aLayer, SHAPE_LINE_CHAIN& aBaseLine );
|
|
|
|
|
|
|
|
bool resetToBaseline( PNS::ROUTER* aRouter, int aLayer, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
SHAPE_LINE_CHAIN& aBaseLine, bool aPrimary );
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN getRectShape() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
VECTOR2I m_end;
|
|
|
|
|
|
|
|
int m_minAmplitude;
|
|
|
|
int m_maxAmplitude;
|
|
|
|
int m_spacing;
|
|
|
|
long long int m_targetLength;
|
|
|
|
int m_targetSkew;
|
|
|
|
bool m_overrideCustomRules;
|
|
|
|
int m_cornerRadiusPercentage;
|
|
|
|
|
|
|
|
PNS::MEANDER_SIDE m_initialSide;
|
|
|
|
|
|
|
|
std::optional<SHAPE_LINE_CHAIN> m_baseLine;
|
|
|
|
std::optional<SHAPE_LINE_CHAIN> m_baseLineCoupled;
|
|
|
|
|
|
|
|
bool m_singleSide;
|
|
|
|
bool m_rounded;
|
|
|
|
|
|
|
|
LENGTH_TUNING_MODE m_tuningMode;
|
|
|
|
|
|
|
|
wxString m_lastNetName;
|
|
|
|
wxString m_tuningInfo;
|
|
|
|
|
|
|
|
PNS::MEANDER_PLACER_BASE::TUNING_STATUS m_tuningStatus;
|
|
|
|
|
|
|
|
// Temp storage during editing
|
|
|
|
std::set<BOARD_ITEM*> m_removedItems;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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-14 11:11:46 +00:00
|
|
|
static NETINFO_ITEM* getCoupledNet( PNS::ROUTER* aRouter, NETINFO_ITEM* aNet )
|
|
|
|
{
|
|
|
|
PNS::RULE_RESOLVER* resolver = aRouter->GetRuleResolver();
|
|
|
|
|
|
|
|
return static_cast<NETINFO_ITEM*>( resolver->DpCoupledNet( aNet ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PCB_GENERATOR_MEANDERS::PCB_GENERATOR_MEANDERS( BOARD_ITEM* aParent, PCB_LAYER_ID aLayer,
|
|
|
|
LENGTH_TUNING_MODE aMode ) :
|
|
|
|
PCB_GENERATOR( aParent, aLayer ),
|
|
|
|
m_singleSide( false ),
|
|
|
|
m_rounded( true ),
|
|
|
|
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_minAmplitude = pcbIUScale.mmToIU( 0.1 );
|
|
|
|
m_maxAmplitude = pcbIUScale.mmToIU( 2.0 );
|
|
|
|
m_spacing = pcbIUScale.mmToIU( 0.6 );
|
|
|
|
m_targetLength = pcbIUScale.mmToIU( 100 );
|
|
|
|
m_targetSkew = pcbIUScale.mmToIU( 0 );
|
2023-10-15 13:55:31 +00:00
|
|
|
m_overrideCustomRules = false;
|
2023-10-14 12:38:25 +00:00
|
|
|
m_end = VECTOR2I( pcbIUScale.mmToIU( 10 ), 0 );
|
|
|
|
m_cornerRadiusPercentage = 100;
|
|
|
|
m_initialSide = PNS::MEANDER_SIDE_DEFAULT;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
static NETINFO_ITEM* snapToNearestTrackPoint( VECTOR2I& aP, BOARD* aBoard, NETINFO_ITEM* aNet )
|
|
|
|
{
|
|
|
|
SEG::ecoord minDistSq = VECTOR2I::ECOORD_MAX;
|
|
|
|
VECTOR2I closestPt = aP;
|
|
|
|
NETINFO_ITEM* closestNet = nullptr;
|
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
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SEG seg( track->GetStart(), track->GetEnd() );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I nearest = seg.NearestPoint( aP );
|
|
|
|
SEG::ecoord distSq = ( nearest - aP ).SquaredEuclideanNorm();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( distSq < minDistSq )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
minDistSq = distSq;
|
|
|
|
closestPt = nearest;
|
|
|
|
closestNet = track->GetNet();
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( minDistSq != VECTOR2I::ECOORD_MAX )
|
2023-10-12 14:45:33 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
aP = closestPt;
|
|
|
|
return closestNet;
|
2023-10-12 14:45:33 +00:00
|
|
|
}
|
2023-10-08 13:04:45 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_GENERATOR_MEANDERS::baselineValid()
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PCB_GENERATOR_MEANDERS* PCB_GENERATOR_MEANDERS::CreateNew( GENERATOR_TOOL* aTool,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
BOARD_CONNECTED_ITEM* aStartItem,
|
|
|
|
LENGTH_TUNING_MODE aMode )
|
|
|
|
{
|
|
|
|
BOARD* board = aStartItem->GetBoard();
|
|
|
|
std::shared_ptr<DRC_ENGINE>& drcEngine = board->GetDesignSettings().m_DRCEngine;
|
|
|
|
DRC_CONSTRAINT constraint;
|
|
|
|
PCB_LAYER_ID layer = aStartItem->GetLayer();
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( aMode == SINGLE && getCoupledNet( aTool->Router(), aStartItem->GetNet() ) )
|
|
|
|
aMode = DIFF_PAIR;
|
2023-10-10 10:08:53 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PCB_GENERATOR_MEANDERS* meander = new PCB_GENERATOR_MEANDERS( board, layer, aMode );
|
2023-10-10 10:08:53 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
constraint = drcEngine->EvalRules( LENGTH_CONSTRAINT, aStartItem, nullptr, layer );
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( aMode == DIFF_PAIR_SKEW )
|
|
|
|
{
|
|
|
|
if( constraint.IsNull() )
|
2023-10-09 20:55:07 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
WX_UNIT_ENTRY_DIALOG dlg( aFrame, _( "Tune Skew" ), _( "Target skew:" ), 0 );
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return nullptr;
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
meander->m_targetSkew = dlg.GetValue();
|
|
|
|
meander->m_overrideCustomRules = true;
|
2023-10-09 20:55:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
meander->m_targetSkew = constraint.GetValue().Opt();
|
|
|
|
meander->m_overrideCustomRules = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( constraint.IsNull() )
|
|
|
|
{
|
|
|
|
WX_UNIT_ENTRY_DIALOG dlg( aFrame, _( "Tune Length" ), _( "Target length:" ),
|
|
|
|
100 * PCB_IU_PER_MM );
|
2023-10-11 16:10:48 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return nullptr;
|
2023-10-11 16:10:48 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
meander->m_targetLength = dlg.GetValue();
|
|
|
|
meander->m_overrideCustomRules = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meander->m_targetLength = constraint.GetValue().Opt();
|
|
|
|
meander->m_overrideCustomRules = false;
|
2023-10-09 20:55:07 +00:00
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
meander->SetFlags( IS_NEW );
|
2023-10-09 21:32:17 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return meander;
|
|
|
|
}
|
2023-10-09 20:55:07 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit )
|
|
|
|
{
|
|
|
|
m_removedItems.clear();
|
|
|
|
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
int layer = GetLayer();
|
|
|
|
PNS::ROUTER* router = aTool->Router();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aTool->ClearRouterCommit();
|
|
|
|
router->SyncWorld();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !baselineValid() )
|
|
|
|
initBaseLines( router, layer, aBoard );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( baselineValid() && !m_overrideCustomRules )
|
|
|
|
{
|
|
|
|
PNS::CONSTRAINT constraint;
|
|
|
|
PNS::RULE_RESOLVER* resolver = router->GetRuleResolver();
|
2023-10-14 11:11:46 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
NETINFO_ITEM* net = snapToNearestTrackPoint( m_origin, aBoard, nullptr );
|
|
|
|
PNS::SEGMENT pnsItem( m_baseLine->CSegment( 0 ), 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 ) )
|
|
|
|
{
|
|
|
|
m_targetLength = constraint.m_Value.Opt();
|
|
|
|
aFrame->GetToolManager()->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* coupledNet = static_cast<NETINFO_ITEM*>( resolver->DpCoupledNet( net ) );
|
|
|
|
PNS::SEGMENT coupledItem( m_baseLineCoupled->CSegment( 0 ), 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,
|
2023-10-14 12:38:25 +00:00
|
|
|
&pnsItem, &coupledItem, layer, &constraint ) )
|
2023-10-14 11:11:46 +00:00
|
|
|
{
|
|
|
|
m_targetLength = constraint.m_Value.Opt();
|
|
|
|
aFrame->GetToolManager()->PostEvent( EVENTS::SelectedItemsModified );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
if( resolver->QueryConstraint( PNS::CONSTRAINT_TYPE::CT_DIFF_PAIR_SKEW,
|
|
|
|
&pnsItem, &coupledItem, layer, &constraint ) )
|
2023-10-14 11:11:46 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
m_targetSkew = constraint.m_Value.Opt();
|
|
|
|
aFrame->GetToolManager()->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 )
|
|
|
|
{
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
for( bool useClearance : { false, true } )
|
|
|
|
{
|
|
|
|
PNS::ITEM_SET candidates = aRouter->QueryHoverItems( aWhere, useClearance );
|
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 )
|
|
|
|
{
|
|
|
|
SEG::ecoord d0 = ( item->Anchor( 0 ) - aWhere ).SquaredEuclideanNorm();
|
|
|
|
SEG::ecoord d1 = ( item->Anchor( 1 ) - 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;
|
|
|
|
point[1] = item->Anchor( 0 );
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( d1 <= dist[1] )
|
|
|
|
{
|
|
|
|
prioritized[1] = linked;
|
|
|
|
dist[1] = d1;
|
|
|
|
point[1] = item->Anchor( 1 );
|
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-10-14 12:38:25 +00:00
|
|
|
wxASSERT( startItem );
|
|
|
|
wxASSERT( endItem );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !startItem || !endItem )
|
|
|
|
return std::nullopt;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINE line = world->AssembleLine( startItem, nullptr, false, true );
|
|
|
|
SHAPE_LINE_CHAIN oldChain = line.CLine();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxCHECK( line.ContainsLink( endItem ), std::nullopt );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
wxASSERT( oldChain.PointOnEdge( aStartOut, 1 ) );
|
|
|
|
wxASSERT( oldChain.PointOnEdge( aEndOut, 1 ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return line;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
bool PCB_GENERATOR_MEANDERS::initBaseLine( PNS::ROUTER* aRouter, int aLayer, BOARD* aBoard,
|
|
|
|
VECTOR2I& aStart, VECTOR2I& aEnd, NETINFO_ITEM* aNet,
|
|
|
|
std::optional<SHAPE_LINE_CHAIN>& aBaseLine )
|
|
|
|
{
|
|
|
|
PNS::NODE* world = aRouter->GetWorld();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
snapToNearestTrackPoint( aStart, aBoard, aNet );
|
|
|
|
snapToNearestTrackPoint( aEnd, aBoard, aNet );
|
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-14 12:38:25 +00:00
|
|
|
PNS::LINE line = world->AssembleLine( startItem, nullptr, false, true );
|
|
|
|
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-14 12:38:25 +00:00
|
|
|
bool PCB_GENERATOR_MEANDERS::initBaseLines( PNS::ROUTER* aRouter, int aLayer, BOARD* aBoard )
|
|
|
|
{
|
|
|
|
m_baseLineCoupled.reset();
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
NETINFO_ITEM* net = snapToNearestTrackPoint( m_origin, aBoard, nullptr );
|
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-14 12:38:25 +00:00
|
|
|
if( NETINFO_ITEM* coupledNet = getCoupledNet( aRouter, net ) )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I coupledStart = m_origin;
|
|
|
|
VECTOR2I coupledEnd = m_end;
|
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-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::removeToBaseline( PNS::ROUTER* aRouter, int aLayer,
|
|
|
|
SHAPE_LINE_CHAIN& aBaseLine )
|
|
|
|
{
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
wxCHECK( pnsLine, /* void */ );
|
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-10-07 03:54:14 +00:00
|
|
|
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit )
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
int undoFlags = 0;
|
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() )
|
|
|
|
{
|
|
|
|
PCB_GENERATOR* group = this;
|
|
|
|
PICKED_ITEMS_LIST undoList;
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* member : group->GetItems() )
|
|
|
|
undoList.PushItem( ITEM_PICKER( nullptr, member, UNDO_REDO::UNGROUP ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
group->RemoveAll();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aFrame->SaveCopyInUndoList( undoList, UNDO_REDO::UNGROUP );
|
|
|
|
undoFlags |= APPEND_UNDO;
|
|
|
|
}
|
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-10-14 12:38:25 +00:00
|
|
|
aTool->ClearRouterCommit();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( baselineValid() )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
removeToBaseline( router, layer, *m_baseLineCoupled );
|
|
|
|
}
|
2023-10-12 14:45:33 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
std::set<BOARD_ITEM*> clearRouterRemovedItems = aTool->GetRouterCommitRemovedItems();
|
|
|
|
std::set<BOARD_ITEM*> clearRouterAddedItems = aTool->GetRouterCommitAddedItems();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* item : clearRouterRemovedItems )
|
|
|
|
{
|
|
|
|
item->ClearSelected();
|
|
|
|
aCommit->Remove( item );
|
2023-10-12 14:45:33 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* item : clearRouterAddedItems )
|
2023-10-12 14:45:33 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
aCommit->Add( item );
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
aCommit->Push( "Remove Tuning Pattern", undoFlags );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::MEANDER_SETTINGS PCB_GENERATOR_MEANDERS::toMeanderSettings()
|
|
|
|
{
|
|
|
|
PNS::MEANDER_SETTINGS settings;
|
|
|
|
|
|
|
|
settings.m_cornerStyle = m_rounded ? PNS::MEANDER_STYLE::MEANDER_STYLE_ROUND
|
|
|
|
: PNS::MEANDER_STYLE::MEANDER_STYLE_CHAMFER;
|
|
|
|
|
|
|
|
settings.m_minAmplitude = m_minAmplitude;
|
|
|
|
settings.m_maxAmplitude = m_maxAmplitude;
|
|
|
|
settings.m_spacing = m_spacing;
|
|
|
|
settings.m_targetLength = m_targetLength;
|
|
|
|
settings.m_targetSkew = m_targetSkew;
|
|
|
|
settings.m_overrideCustomRules = m_overrideCustomRules;
|
|
|
|
settings.m_singleSided = m_singleSide;
|
|
|
|
settings.m_segmentSide = m_initialSide;
|
|
|
|
settings.m_cornerRadiusPercentage = m_cornerRadiusPercentage;
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::fromMeanderSettings( const PNS::MEANDER_SETTINGS& aSettings )
|
|
|
|
{
|
|
|
|
m_rounded = aSettings.m_cornerStyle == PNS::MEANDER_STYLE::MEANDER_STYLE_ROUND;
|
|
|
|
m_minAmplitude = aSettings.m_minAmplitude;
|
|
|
|
m_maxAmplitude = aSettings.m_maxAmplitude;
|
|
|
|
m_spacing = aSettings.m_spacing;
|
|
|
|
m_targetLength = aSettings.m_targetLength;
|
|
|
|
m_targetSkew = aSettings.m_targetSkew;
|
|
|
|
m_overrideCustomRules = aSettings.m_overrideCustomRules;
|
|
|
|
m_singleSide = aSettings.m_singleSided;
|
|
|
|
m_initialSide = aSettings.m_segmentSide;
|
|
|
|
m_cornerRadiusPercentage = aSettings.m_cornerRadiusPercentage;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::ROUTER_MODE PCB_GENERATOR_MEANDERS::toPNSMode()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
bool PCB_GENERATOR_MEANDERS::resetToBaseline( PNS::ROUTER* aRouter, int aLayer,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
SHAPE_LINE_CHAIN& aBaseLine, bool aPrimary )
|
|
|
|
{
|
|
|
|
PNS::NODE* world = aRouter->GetWorld();
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
wxCHECK( pnsLine, false );
|
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-10-14 12:38:25 +00:00
|
|
|
for( PNS::LINKED_ITEM* pnsItem : pnsLine->Links() )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
if( BOARD_ITEM* item = pnsItem->Parent() )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
aFrame->GetCanvas()->GetView()->Hide( item, true, true );
|
|
|
|
m_removedItems.insert( item );
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
world->Remove( *pnsLine );
|
2023-10-09 20:48:34 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::LINE straightLine( *pnsLine, straightChain );
|
2023-10-09 20:48:34 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
world->Add( straightLine, false );
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-09 20:48:34 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
bool PCB_GENERATOR_MEANDERS::Update( GENERATOR_TOOL* aTool, BOARD* aBoard,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit )
|
|
|
|
{
|
|
|
|
PNS::ROUTER* router = aTool->Router();
|
|
|
|
PNS_KICAD_IFACE* iface = aTool->GetInterface();
|
|
|
|
int layer = GetLayer();
|
|
|
|
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
if( resetToBaseline( router, layer, aFrame, *m_baseLine, true ) )
|
|
|
|
{
|
|
|
|
m_origin = m_baseLine->CPoint( 0 );
|
|
|
|
m_end = m_baseLine->CPoint( -1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
initBaseLines( router, layer, aBoard );
|
|
|
|
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-10-15 13:13:32 +00:00
|
|
|
if( !resetToBaseline( router, layer, aFrame, *m_baseLineCoupled, false ) )
|
|
|
|
{
|
|
|
|
initBaseLines( router, layer, aBoard );
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 16:53:26 +00:00
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
router->SetMode( toPNSMode() );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !router->StartRouting( startSnapPoint, startItem, layer ) )
|
|
|
|
return false;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
auto placer = static_cast<PNS::MEANDER_PLACER_BASE*>( router->Placer() );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
PNS::MEANDER_SETTINGS settings = toMeanderSettings();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
placer->UpdateSettings( settings );
|
|
|
|
router->Move( m_end, nullptr );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
m_lastNetName = iface->GetNetName( startItem->Net() );
|
|
|
|
m_tuningInfo = placer->TuningInfo( aFrame->GetUserUnits() );
|
|
|
|
m_tuningStatus = placer->TuningStatus();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-10-12 16:53:26 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit,
|
|
|
|
const wxString& aCommitMsg, int aCommitFlags )
|
|
|
|
{
|
|
|
|
PNS::ROUTER* router = aTool->Router();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( router->RoutingInProgress() )
|
|
|
|
{
|
|
|
|
router->FixRoute( m_end, nullptr, true );
|
|
|
|
router->StopRouting();
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
std::set<BOARD_ITEM*> routerRemovedItems = aTool->GetRouterCommitRemovedItems();
|
|
|
|
std::set<BOARD_ITEM*> routerAddedItems = aTool->GetRouterCommitAddedItems();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* item : m_removedItems )
|
2023-10-07 03:54:14 +00:00
|
|
|
{
|
2023-10-14 12:38:25 +00:00
|
|
|
aFrame->GetCanvas()->GetView()->Hide( item, false );
|
|
|
|
aCommit->Remove( item );
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
m_removedItems.clear();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
for( BOARD_ITEM* item : routerRemovedItems )
|
|
|
|
{
|
|
|
|
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-10-14 12:38:25 +00:00
|
|
|
item->SetSelected();
|
|
|
|
AddItem( item );
|
|
|
|
aCommit->Add( item );
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
// Store isNew as BOARD_COMMIT::Push() is going to clear it.
|
|
|
|
bool isNew = IsNew();
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( aCommitMsg.IsEmpty() )
|
2023-10-15 16:02:15 +00:00
|
|
|
aCommit->Push( _( "Edit Tuning Pattern" ), aCommitFlags );
|
2023-10-14 12:38:25 +00:00
|
|
|
else
|
|
|
|
aCommit->Push( aCommitMsg, aCommitFlags );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( isNew && !GetItems().empty() )
|
|
|
|
{
|
|
|
|
PICKED_ITEMS_LIST undoList;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* member : GetItems() )
|
|
|
|
undoList.PushItem( ITEM_PICKER( nullptr, member, UNDO_REDO::REGROUP ) );
|
|
|
|
|
|
|
|
aFrame->AppendCopyToUndoList( undoList, UNDO_REDO::REGROUP );
|
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-12 16:53:26 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard,
|
|
|
|
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit )
|
|
|
|
{
|
|
|
|
for( BOARD_ITEM* item : m_removedItems )
|
|
|
|
aFrame->GetCanvas()->GetView()->Hide( item, false );
|
2023-10-12 16:53:26 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
m_removedItems.clear();
|
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-14 12:38:25 +00:00
|
|
|
bool PCB_GENERATOR_MEANDERS::MakeEditPoints( std::shared_ptr<EDIT_POINTS> points ) const
|
|
|
|
{
|
|
|
|
VECTOR2I centerlineOffset;
|
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-10-14 12:38:25 +00:00
|
|
|
centerlineOffset = ( m_baseLineCoupled->CPoint( 0 ) - m_origin ) / 2;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
points->AddPoint( m_origin + centerlineOffset );
|
|
|
|
points->AddPoint( m_end + centerlineOffset );
|
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
|
|
|
int offset = m_maxAmplitude;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_initialSide == -1 )
|
|
|
|
offset *= -1;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I widthHandleOffset = ( base.B - base.A ).Perpendicular().Resize( offset );
|
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 =
|
|
|
|
widthHandleOffset + ( base.B - base.A ).Resize( KiROUND( 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-14 12:38:25 +00:00
|
|
|
bool PCB_GENERATOR_MEANDERS::UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
|
|
|
|
BOARD_COMMIT* aCommit )
|
|
|
|
{
|
|
|
|
VECTOR2I centerlineOffset;
|
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-10-14 12:38:25 +00:00
|
|
|
centerlineOffset = ( m_baseLineCoupled->CPoint( 0 ) - m_origin ) / 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;
|
|
|
|
m_end = aEditPoints->Point( 1 ).GetPosition() - centerlineOffset;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
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 )
|
|
|
|
m_initialSide = PNS::MEANDER_SIDE_LEFT;
|
|
|
|
else
|
|
|
|
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-14 12:38:25 +00:00
|
|
|
bool PCB_GENERATOR_MEANDERS::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints )
|
|
|
|
{
|
|
|
|
VECTOR2I centerlineOffset;
|
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-10-14 12:38:25 +00:00
|
|
|
centerlineOffset = ( m_baseLineCoupled->CPoint( 0 ) - m_origin ) / 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-14 12:38:25 +00:00
|
|
|
int offset = m_maxAmplitude;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_initialSide == -1 )
|
|
|
|
offset *= -1;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
VECTOR2I widthHandleOffset = ( base.B - base.A ).Perpendicular().Resize( offset );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aEditPoints->Point( 0 ).SetPosition( m_origin + centerlineOffset );
|
|
|
|
aEditPoints->Point( 1 ).SetPosition( m_end + centerlineOffset );
|
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-15 16:58:28 +00:00
|
|
|
VECTOR2I spacingHandleOffset = widthHandleOffset
|
2023-10-14 12:38:25 +00:00
|
|
|
+ ( base.B - base.A ).Resize( KiROUND( 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
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN PCB_GENERATOR_MEANDERS::getRectShape() const
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN chain;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_baseLine )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN cl = *m_baseLine;
|
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-10-14 12:38:25 +00:00
|
|
|
{
|
2023-10-15 13:13:32 +00:00
|
|
|
for( int i = 0; i < cl.PointCount() - 1 && i < m_baseLineCoupled->PointCount(); ++i )
|
2023-10-14 12:38:25 +00:00
|
|
|
cl.SetPoint( i, ( cl.CPoint( i ) + m_baseLineCoupled->CPoint( i ) ) / 2 );
|
2023-10-15 13:13:32 +00:00
|
|
|
|
|
|
|
cl.SetPoint( -1, ( cl.CPoint( -1 ) + m_baseLineCoupled->CPoint( -1 ) ) / 2 );
|
2023-10-14 12:38:25 +00:00
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
bool singleSided = m_tuningMode != DIFF_PAIR && m_singleSide;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( singleSided )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN left, right;
|
2023-10-11 10:48:43 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( cl.OffsetLine( m_maxAmplitude, CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_LOW_DEF,
|
|
|
|
left, right, true ) )
|
|
|
|
{
|
|
|
|
chain.Append( cl.CPoint( 0 ) );
|
|
|
|
chain.Append( m_initialSide >= 0 ? right : left );
|
|
|
|
chain.Append( cl.CPoint( -1 ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return chain;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
singleSided = false;
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !singleSided )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET poly;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
poly.OffsetLineChain( cl, m_maxAmplitude * 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
|
|
|
|
ARC_LOW_DEF, false );
|
|
|
|
|
|
|
|
if( poly.OutlineCount() > 0 )
|
|
|
|
{
|
|
|
|
chain = poly.Outline( 0 );
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
return chain;
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
|
|
|
|
{
|
|
|
|
if( !IsSelected() )
|
|
|
|
return;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
KIGFX::PREVIEW::DRAW_CONTEXT ctx( *aView );
|
|
|
|
int size = KiROUND( aView->ToWorld( EDIT_POINT::POINT_SIZE ) * 0.8 );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( m_baseLine )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < m_baseLine->SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
SEG seg = m_baseLine->CSegment( i );
|
|
|
|
ctx.DrawLine( seg.A, seg.B, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ctx.DrawLine( m_origin, m_end, false );
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
if( m_tuningMode == DIFF_PAIR && m_baseLineCoupled )
|
2023-10-14 12:38:25 +00:00
|
|
|
{
|
|
|
|
for( int i = 0; i < m_baseLineCoupled->SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
SEG seg = m_baseLineCoupled->CSegment( i );
|
|
|
|
ctx.DrawLine( seg.A, seg.B, false );
|
|
|
|
}
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
SHAPE_LINE_CHAIN chain = getRectShape();
|
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-14 12:38:25 +00:00
|
|
|
const STRING_ANY_MAP PCB_GENERATOR_MEANDERS::GetProperties() const
|
|
|
|
{
|
|
|
|
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 ) );
|
|
|
|
props.set( "initial_side", sideToString( m_initialSide ) );
|
|
|
|
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 );
|
|
|
|
props.set( "corner_radius_percent", m_cornerRadiusPercentage );
|
|
|
|
props.set( "single_sided", m_singleSide );
|
|
|
|
props.set( "rounded", m_rounded );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
props.set_iu( "max_amplitude", m_maxAmplitude );
|
|
|
|
props.set_iu( "min_spacing", m_spacing );
|
|
|
|
props.set_iu( "target_length", m_targetLength );
|
|
|
|
props.set_iu( "target_skew", m_targetSkew );
|
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 );
|
|
|
|
props.set( "override_custom_rules", 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-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::SetProperties( const STRING_ANY_MAP& aProps )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
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 );
|
|
|
|
aProps.get_to( "corner_radius_percent", m_cornerRadiusPercentage );
|
|
|
|
aProps.get_to( "single_sided", m_singleSide );
|
|
|
|
aProps.get_to( "side", m_initialSide );
|
|
|
|
aProps.get_to( "rounded", m_rounded );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aProps.get_to_iu( "max_amplitude", m_maxAmplitude );
|
|
|
|
aProps.get_to_iu( "min_spacing", m_spacing );
|
|
|
|
aProps.get_to_iu( "target_length", m_targetLength );
|
|
|
|
aProps.get_to_iu( "target_skew", m_targetSkew );
|
|
|
|
aProps.get_to( "override_custom_rules", 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-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame )
|
|
|
|
{
|
|
|
|
PNS::MEANDER_SETTINGS settings = toMeanderSettings();
|
|
|
|
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 )
|
|
|
|
settings.m_targetLength = constraint.GetValue().Opt();
|
|
|
|
}
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
DIALOG_TUNING_PATTERN_PROPERTIES dlg( aEditFrame, settings, toPNSMode(), 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-10 10:55:57 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
fromMeanderSettings( settings );
|
2023-10-10 10:55:57 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
commit.Push( _( "Edit Tuning Pattern" ) );
|
2023-10-10 10:55:57 +00:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aEditFrame->GetToolManager()->PostAction<PCB_GENERATOR*>( PCB_ACTIONS::regenerateItem, this );
|
|
|
|
}
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::UpdateStatus( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
|
|
|
|
STATUS_TEXT_POPUP* aPopup )
|
|
|
|
{
|
|
|
|
auto* placer = dynamic_cast<PNS::MEANDER_PLACER_BASE*>( aTool->Router()->Placer() );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
if( !placer )
|
|
|
|
return;
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
aPopup->SetText( placer->TuningInfo( aFrame->GetUserUnits() ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
// Determine the background color first and choose a contrasting value
|
|
|
|
COLOR4D bg( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
|
|
|
|
double h, s, l;
|
|
|
|
bg.ToHSL( h, s, l );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
switch( placer->TuningStatus() )
|
|
|
|
{
|
|
|
|
case PNS::MEANDER_PLACER_BASE::TUNED:
|
|
|
|
if( l < 0.5 )
|
|
|
|
aPopup->SetTextColor( wxColor( 127, 200, 127 ) );
|
|
|
|
else
|
|
|
|
aPopup->SetTextColor( wxColor( 0, 92, 0 ) );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-14 12:38:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS::MEANDER_PLACER_BASE::TOO_SHORT:
|
|
|
|
if( l < 0.5 )
|
|
|
|
aPopup->SetTextColor( wxColor( 242, 100, 126 ) );
|
|
|
|
else
|
|
|
|
aPopup->SetTextColor( wxColor( 122, 0, 0 ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS::MEANDER_PLACER_BASE::TOO_LONG:
|
|
|
|
if( l < 0.5 )
|
|
|
|
aPopup->SetTextColor( wxColor( 66, 184, 235 ) );
|
|
|
|
else
|
|
|
|
aPopup->SetTextColor( wxColor( 19, 19, 195 ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-10-09 20:48:34 +00:00
|
|
|
|
2023-10-07 03:54:14 +00:00
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
void PCB_GENERATOR_MEANDERS::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto getMinOptMax =
|
|
|
|
[&]( const MINOPTMAX<int>& v )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( v.HasMin() )
|
|
|
|
{
|
|
|
|
msg += wxString::Format( _( "min %s" ), aFrame->MessageTextFromValue( v.Min() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( v.HasOpt() )
|
|
|
|
{
|
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
msg += wxS( "; " );
|
|
|
|
|
|
|
|
msg += wxString::Format( _( "opt %s" ), aFrame->MessageTextFromValue( v.Opt() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( v.HasMax() )
|
|
|
|
{
|
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
msg += wxS( "; " );
|
|
|
|
|
|
|
|
msg += wxString::Format( _( "max %s" ), aFrame->MessageTextFromValue( v.Max() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( m_tuningMode == DIFF_PAIR_SKEW )
|
|
|
|
{
|
|
|
|
constraint = drcEngine->EvalRules( SKEW_CONSTRAINT, primaryItem, coupledItem, m_layer );
|
|
|
|
|
|
|
|
if( constraint.IsNull() || m_overrideCustomRules )
|
|
|
|
{
|
|
|
|
msg = aFrame->MessageTextFromValue( m_targetSkew );
|
|
|
|
|
|
|
|
aList.emplace_back( wxString::Format( _( "Target Skew: %s" ), msg ),
|
|
|
|
wxString::Format( _( "(from tuning pattern properties)" ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = getMinOptMax( constraint.GetValue() );
|
|
|
|
|
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
{
|
|
|
|
aList.emplace_back( wxString::Format( _( "Skew Constraints: %s." ), msg ),
|
|
|
|
wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
constraint = drcEngine->EvalRules( LENGTH_CONSTRAINT, primaryItem, coupledItem, m_layer );
|
|
|
|
|
|
|
|
if( constraint.IsNull() || m_overrideCustomRules )
|
|
|
|
{
|
|
|
|
msg = aFrame->MessageTextFromValue( (double) m_targetLength );
|
|
|
|
|
|
|
|
aList.emplace_back( wxString::Format( _( "Target Length: %s" ), msg ),
|
|
|
|
wxString::Format( _( "(from tuning pattern properties)" ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = getMinOptMax( constraint.GetValue() );
|
|
|
|
|
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
{
|
|
|
|
aList.emplace_back( wxString::Format( _( "Length Constraints: %s." ), msg ),
|
|
|
|
wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString PCB_GENERATOR_MEANDERS::DISPLAY_NAME = _HKI( "Tuning Pattern" );
|
2023-10-07 03:54:14 +00:00
|
|
|
const wxString PCB_GENERATOR_MEANDERS::GENERATOR_TYPE = wxS( "meanders" );
|
|
|
|
|
|
|
|
|
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-07 03:54:14 +00:00
|
|
|
int DRAWING_TOOL::PlaceMeander( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
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-10-14 12:38:25 +00:00
|
|
|
LENGTH_TUNING_MODE mode = fromPNSMode( aEvent.Parameter<PNS::ROUTER_MODE>() );
|
2023-10-11 13:43:54 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
BOARD* board = m_frame->GetBoard();
|
|
|
|
PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
|
|
|
GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
|
|
|
|
GENERATOR_TOOL* generatorTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
|
2023-10-11 14:50:15 +00:00
|
|
|
PNS::ROUTER* router = generatorTool->Router();
|
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-10-11 14:50:15 +00:00
|
|
|
auto updateMeander =
|
|
|
|
[&]()
|
|
|
|
{
|
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-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->EditStart( generatorTool, m_board, m_frame, nullptr );
|
|
|
|
m_tuningPattern->Update( generatorTool, m_board, m_frame, nullptr );
|
2023-10-11 14:50:15 +00:00
|
|
|
|
|
|
|
m_statusPopup->Popup();
|
|
|
|
canvas()->SetStatusPopup( m_statusPopup.get() );
|
|
|
|
|
|
|
|
m_view->Update( &m_preview );
|
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->UpdateStatus( generatorTool, m_frame, m_statusPopup.get() );
|
2023-10-11 14:50:15 +00:00
|
|
|
m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() || evt->IsActivate() )
|
|
|
|
{
|
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 already made; clean up meander preview
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->EditRevert( generatorTool, m_board, m_frame, nullptr );
|
2023-10-09 20:46:24 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
m_preview.Clear();
|
2023-10-07 03:54:14 +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-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
|
|
|
|
|
|
|
BOARD_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
|
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
if( !m_pickerItem )
|
2023-10-09 14:22:16 +00:00
|
|
|
{
|
2023-10-11 13:43:54 +00:00
|
|
|
m_pickerItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
|
2023-10-11 16:10:48 +00:00
|
|
|
generatorTool->HighlightNets( m_pickerItem );
|
2023-10-09 14:22:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-11 13:43:54 +00:00
|
|
|
m_pickerItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
|
2023-10-11 16:10:48 +00:00
|
|
|
generatorTool->UpdateHighlightedNets( m_pickerItem );
|
2023-10-09 14:22:16 +00:00
|
|
|
}
|
2023-10-11 13:43:54 +00:00
|
|
|
}
|
|
|
|
else
|
2023-10-09 14:22:16 +00:00
|
|
|
{
|
2023-10-11 13:43:54 +00:00
|
|
|
// First click already made; we're in preview-meander mode
|
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->SetEnd( cursorPos );
|
2023-10-11 14:50:15 +00:00
|
|
|
updateMeander();
|
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
|
|
|
{
|
|
|
|
// First click; create a meander
|
|
|
|
|
|
|
|
generatorTool->HighlightNets( nullptr );
|
|
|
|
|
|
|
|
m_frame->SetActiveLayer( m_pickerItem->GetLayer() );
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern = PCB_GENERATOR_MEANDERS::CreateNew( generatorTool, m_frame,
|
2023-10-11 16:10:48 +00:00
|
|
|
m_pickerItem, mode );
|
|
|
|
|
|
|
|
int dummyDist;
|
|
|
|
int dummyClearance = std::numeric_limits<int>::max() / 2;
|
|
|
|
VECTOR2I closestPt;
|
|
|
|
|
|
|
|
m_pickerItem->GetEffectiveShape()->Collide( cursorPos, dummyClearance,
|
|
|
|
&dummyDist, &closestPt );
|
2023-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->SetPosition( closestPt );
|
|
|
|
m_tuningPattern->SetEnd( closestPt );
|
2023-10-11 16:10:48 +00:00
|
|
|
|
2023-10-15 16:02:15 +00:00
|
|
|
m_preview.Add( m_tuningPattern );
|
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-10-15 16:02:15 +00:00
|
|
|
m_tuningPattern->EditStart( generatorTool, m_board, m_frame, &commit );
|
|
|
|
m_tuningPattern->Update( generatorTool, m_board, m_frame, &commit );
|
|
|
|
m_tuningPattern->EditPush( generatorTool, m_board, m_frame, &commit, _( "Tune" ) );
|
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-11 14:50:15 +00:00
|
|
|
updateMeander();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-11 14:50:15 +00:00
|
|
|
updateMeander();
|
|
|
|
}
|
|
|
|
}
|
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-10-11 13:43:54 +00:00
|
|
|
canvas()->SetStatusPopup( nullptr );
|
|
|
|
m_statusPopup->Hide();
|
2023-10-09 20:46:24 +00:00
|
|
|
|
2023-10-11 16:10:48 +00:00
|
|
|
generatorTool->HighlightNets( nullptr );
|
2023-10-11 13:09:53 +00:00
|
|
|
|
2023-10-11 13:43:54 +00:00
|
|
|
m_preview.Clear();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct PCB_GENERATOR_MEANDERS_DESC
|
|
|
|
{
|
|
|
|
PCB_GENERATOR_MEANDERS_DESC()
|
|
|
|
{
|
|
|
|
ENUM_MAP<LENGTH_TUNING_MODE>::Instance()
|
|
|
|
.Map( LENGTH_TUNING_MODE::SINGLE, _HKI( "Single track" ) )
|
2023-10-14 11:11:46 +00:00
|
|
|
.Map( LENGTH_TUNING_MODE::DIFF_PAIR, _HKI( "Diff. pair" ) )
|
2023-10-07 03:54:14 +00:00
|
|
|
.Map( LENGTH_TUNING_MODE::DIFF_PAIR_SKEW, _HKI( "Diff. pair Skew" ) );
|
|
|
|
|
|
|
|
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();
|
|
|
|
REGISTER_TYPE( PCB_GENERATOR_MEANDERS );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_GENERATOR_MEANDERS, PCB_GENERATOR> );
|
|
|
|
propMgr.AddTypeCast( new TYPE_CAST<PCB_GENERATOR_MEANDERS, BOARD_ITEM> );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_GENERATOR_MEANDERS ), TYPE_HASH( PCB_GENERATOR ) );
|
|
|
|
propMgr.InheritsAfter( TYPE_HASH( PCB_GENERATOR_MEANDERS ), TYPE_HASH( BOARD_ITEM ) );
|
|
|
|
|
2023-10-15 13:13:32 +00:00
|
|
|
const wxString groupTab = _HKI( "Pattern Properties" );
|
2023-10-07 03:54:14 +00:00
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, int>(
|
|
|
|
_HKI( "End X" ), &PCB_GENERATOR_MEANDERS::SetEndX,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetEndX, PROPERTY_DISPLAY::PT_SIZE,
|
|
|
|
ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, int>(
|
|
|
|
_HKI( "End Y" ), &PCB_GENERATOR_MEANDERS::SetEndY,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetEndY, PROPERTY_DISPLAY::PT_SIZE,
|
|
|
|
ORIGIN_TRANSFORMS::ABS_Y_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<PCB_GENERATOR_MEANDERS, LENGTH_TUNING_MODE>(
|
|
|
|
_HKI( "Tuning mode" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetTuningMode,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetTuningMode ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, int>(
|
|
|
|
_HKI( "Min amplitude" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetMinAmplitude,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetMinAmplitude,
|
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, int>(
|
|
|
|
_HKI( "Max amplitude" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetMaxAmplitude,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetMaxAmplitude,
|
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<PCB_GENERATOR_MEANDERS, PNS::MEANDER_SIDE>(
|
|
|
|
_HKI( "Initial side" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetInitialSide,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetInitialSide ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, int>(
|
|
|
|
_HKI( "Min spacing" ), &PCB_GENERATOR_MEANDERS::SetSpacing,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetSpacing, PROPERTY_DISPLAY::PT_SIZE,
|
|
|
|
ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, int>(
|
|
|
|
_HKI( "Corner radius %" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetCornerRadiusPercentage,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetCornerRadiusPercentage,
|
|
|
|
PROPERTY_DISPLAY::PT_DEFAULT, ORIGIN_TRANSFORMS::NOT_A_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-11 13:09:53 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, long long int>(
|
2023-10-07 03:54:14 +00:00
|
|
|
_HKI( "Target length" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetTargetLength,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetTargetLength,
|
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, int>(
|
|
|
|
_HKI( "Target skew" ), &PCB_GENERATOR_MEANDERS::SetTargetSkew,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetTargetSkew,
|
|
|
|
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-11 10:48:43 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, bool>(
|
|
|
|
_HKI( "Override custom rules" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetOverrideCustomRules,
|
|
|
|
&PCB_GENERATOR_MEANDERS::GetOverrideCustomRules ),
|
|
|
|
groupTab );
|
|
|
|
|
2023-10-07 03:54:14 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, bool>(
|
|
|
|
_HKI( "Single-sided" ),
|
|
|
|
&PCB_GENERATOR_MEANDERS::SetSingleSided,
|
|
|
|
&PCB_GENERATOR_MEANDERS::IsSingleSided ),
|
|
|
|
groupTab );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<PCB_GENERATOR_MEANDERS, bool>(
|
|
|
|
_HKI( "Rounded" ), &PCB_GENERATOR_MEANDERS::SetRounded,
|
|
|
|
&PCB_GENERATOR_MEANDERS::IsRounded ),
|
|
|
|
groupTab );
|
|
|
|
}
|
|
|
|
} _PCB_GENERATOR_MEANDERS_DESC;
|
|
|
|
|
|
|
|
ENUM_TO_WXANY( LENGTH_TUNING_MODE )
|
|
|
|
ENUM_TO_WXANY( PNS::MEANDER_SIDE )
|
|
|
|
|
|
|
|
static GENERATORS_MGR::REGISTER<PCB_GENERATOR_MEANDERS> registerMe;
|