Teardrop: Simplify code.

This commit is contained in:
jean-pierre charras 2022-01-23 12:57:06 +01:00
parent 1b42152ba0
commit 712b304da7
3 changed files with 22 additions and 96 deletions

View File

@ -94,6 +94,14 @@ public:
} }
~TEARDROP_DIALOG() ~TEARDROP_DIALOG()
{
TransferToParamList();
}
/**
* Copy the settings from dialog to the current board settings
*/
void TransferToParamList()
{ {
int shape_seg_count = GetCurvePointCount(); int shape_seg_count = GetCurvePointCount();
TEARDROP_PARAMETERS_LIST* prmsList = m_brdSettings->GetTeadropParamsList(); TEARDROP_PARAMETERS_LIST* prmsList = m_brdSettings->GetTeadropParamsList();
@ -195,34 +203,10 @@ void PCB_EDIT_FRAME::OnRunTeardropTool( wxCommandEvent& event )
BOARD_COMMIT committer( this ); BOARD_COMMIT committer( this );
dlg.TransferToParamList();
TEARDROP_MANAGER trdm( GetBoard(), this ); TEARDROP_MANAGER trdm( GetBoard(), this );
int shape_seg_count = dlg.GetCurvePointCount();
trdm.SetTeardropMaxSize( TARGET_ROUND, dlg.GetTeardropMaxLenRound(),
dlg.GetTeardropMaxHeightRound() );
trdm.SetTeardropSizeRatio( TARGET_ROUND, dlg.GetTeardropLenPercentRound(),
dlg.GetTeardropSizePercentRound() );
trdm.SetTeardropCurvedPrm( TARGET_ROUND, (dlg.CurvedShapeOption() & CURVED_OPTION_ROUND)
? shape_seg_count : 0 );
trdm.SetTeardropMaxSize( TARGET_RECT, dlg.GetTeardropMaxLenRect(),
dlg.GetTeardropMaxHeightRect() );
trdm.SetTeardropSizeRatio( TARGET_RECT, dlg.GetTeardropLenPercentRect(),
dlg.GetTeardropSizePercentRect() );
trdm.SetTeardropCurvedPrm( TARGET_RECT, (dlg.CurvedShapeOption() & CURVED_OPTION_RECT)
? shape_seg_count : 0 );
trdm.SetTeardropMaxSize( TARGET_TRACK, dlg.GetTeardropMaxLenTrack(),
dlg.GetTeardropMaxHeightTrack() );
trdm.SetTeardropSizeRatio( TARGET_TRACK, dlg.GetTeardropLenPercentTrack(),
dlg.GetTeardropSizePercentTrack() );
trdm.SetTeardropCurvedPrm( TARGET_TRACK, (dlg.CurvedShapeOption() & CURVED_OPTION_TRACK)
? shape_seg_count : 0 );
const bool discardTeardropInSameZone = true; const bool discardTeardropInSameZone = true;
trdm.SetTargets( dlg.TeardropOnPadVia(), dlg.RoundShapesOnly(),
dlg.IncludeNotPTH(), dlg.TeardropOnTracks() );
int added_count = trdm.SetTeardrops( &committer, int added_count = trdm.SetTeardrops( &committer,
discardTeardropInSameZone, discardTeardropInSameZone,

View File

@ -43,13 +43,11 @@
#define MAGIC_TEARDROP_ZONE_ID 30000 #define MAGIC_TEARDROP_ZONE_ID 30000
void TEARDROP_MANAGER::SetTargets( bool aApplyToPadVias, bool aApplyToRoundShapesOnly, TEARDROP_MANAGER::TEARDROP_MANAGER( BOARD* aBoard, PCB_EDIT_FRAME* aFrame )
bool aApplyToSurfacePads, bool aApplyToTracks )
{ {
m_applyToViaPads = aApplyToPadVias; m_board = aBoard;
m_applyToRoundShapesOnly = aApplyToRoundShapesOnly; m_prmsList = m_board->GetDesignSettings().GetTeadropParamsList();
m_applyToSurfacePads = aApplyToSurfacePads; m_tolerance = 0;
m_applyToTracks = aApplyToTracks;
} }
@ -101,10 +99,11 @@ int TEARDROP_MANAGER::SetTeardrops( BOARD_COMMIT* aCommitter,
// (custom pads are not collected) // (custom pads are not collected)
std::vector< VIAPAD > viapad_list; std::vector< VIAPAD > viapad_list;
if( m_applyToViaPads ) if( m_prmsList->m_TargetViasPads )
collectVias( viapad_list ); collectVias( viapad_list );
collectPadsCandidate( viapad_list, m_applyToViaPads, m_applyToRoundShapesOnly, m_applyToSurfacePads ); collectPadsCandidate( viapad_list, m_prmsList->m_TargetViasPads,
m_prmsList->m_UseRoundShapesOnly, m_prmsList->m_TargetPadsWithNoHole );
TRACK_BUFFER trackLookupList; TRACK_BUFFER trackLookupList;
@ -150,9 +149,9 @@ int TEARDROP_MANAGER::SetTeardrops( BOARD_COMMIT* aCommitter,
TEARDROP_PARAMETERS* currParams; TEARDROP_PARAMETERS* currParams;
if( viapad.m_IsRound ) if( viapad.m_IsRound )
currParams = m_Parameters.GetParameters( TARGET_ROUND ); currParams = m_prmsList->GetParameters( TARGET_ROUND );
else else
currParams = m_Parameters.GetParameters( TARGET_RECT ); currParams = m_prmsList->GetParameters( TARGET_RECT );
// Ensure a teardrop shape can be built: // Ensure a teardrop shape can be built:
// The track width must be < teardrop height // The track width must be < teardrop height
@ -185,7 +184,7 @@ int TEARDROP_MANAGER::SetTeardrops( BOARD_COMMIT* aCommitter,
int track2trackCount = 0; int track2trackCount = 0;
if( m_applyToTracks ) if( m_prmsList->m_TargetTrack2Track )
track2trackCount = addTeardropsOnTracks( aCommitter ); track2trackCount = addTeardropsOnTracks( aCommitter );
// Now set priority of teardrops now all teardrops are added // Now set priority of teardrops now all teardrops are added
@ -263,7 +262,7 @@ int TEARDROP_MANAGER::addTeardropsOnTracks( BOARD_COMMIT* aCommitter )
collectVias( viapad_list ); collectVias( viapad_list );
collectPadsCandidate( viapad_list, true, true, true ); collectPadsCandidate( viapad_list, true, true, true );
TEARDROP_PARAMETERS* currParams = m_Parameters.GetParameters( TARGET_TRACK ); TEARDROP_PARAMETERS* currParams = m_prmsList->GetParameters( TARGET_TRACK );
// Explore groups (a group is a set of tracks on the same layer and the same net): // Explore groups (a group is a set of tracks on the same layer and the same net):
for( auto grp : trackLookupList.GetBuffer() ) for( auto grp : trackLookupList.GetBuffer() )

View File

@ -87,14 +87,7 @@ public:
TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track TD_TYPE_TRACKEND // specify a teardrop on a rond end of a wide track
}; };
TEARDROP_MANAGER( BOARD* aBoard, PCB_EDIT_FRAME* aFrame ) : TEARDROP_MANAGER( BOARD* aBoard, PCB_EDIT_FRAME* aFrame );
m_tolerance( 0 ),
m_applyToViaPads( true ),
m_applyToRoundShapesOnly( false ),
m_applyToSurfacePads( true ),
m_board( aBoard )
{
}
/** /**
* Set teardrops on a teardrop free board * Set teardrops on a teardrop free board
@ -119,52 +112,6 @@ public:
*/ */
int RemoveTeardrops( BOARD_COMMIT* aCommitter, bool aCommitAfterRemove ); int RemoveTeardrops( BOARD_COMMIT* aCommitter, bool aCommitAfterRemove );
/**
* Set max allowed length and height for teardrops in IU.
* a value <= 0 disable the constraint
*/
void SetTeardropMaxSize( TARGET_TD aTdType, int aMaxLen, int aMaxHeight )
{
m_Parameters.GetParameters( aTdType )->SetTeardropMaxSize( aMaxLen, aMaxHeight );
}
/**
* Set prefered length and height ratio for teardrops
* the prefered length and height are VIAPAD width * aLenghtRatio and
* VIAPAD width * aHeightRatio
*/
void SetTeardropSizeRatio( TARGET_TD aTdType, double aLenghtRatio = 0.5, double aHeightRatio = 1.0 )
{
m_Parameters.GetParameters( aTdType )->SetTeardropSizeRatio( aLenghtRatio, aHeightRatio );
}
/**
* Set the params for teardrop using curved shape
* note: if aSegCount is < 3, the shape uses a straight line
*/
void SetTeardropCurvedPrm( TARGET_TD aTdType, int aCurveSegCount = 0 )
{
m_Parameters.GetParameters( aTdType )->SetTeardropCurvedPrm( aCurveSegCount );
}
/**
* Define the items used to add a teardrop
* @param aApplyToPadVias = true to add Td to vias and PTH
* @param aApplyToRoundShapesOnly = true to restrict Td on round PTH
* @param aApplyToSurfacePads = true to add Td to not drilled pads (like SMD)
* @param aApplyToTracks = true to add Td to tracks connected point when having
* different sizes
*/
void SetTargets( bool aApplyToPadVias, bool aApplyToRoundShapesOnly,
bool aApplyToSurfacePads, bool aApplyToTracks );
/**
* the list of available TEARDROP_PARAMETERS items
* at least for round, rect PADVIA shapes and tracks
*/
TEARDROP_PARAMETERS_LIST m_Parameters;
private: private:
/** /**
@ -301,12 +248,8 @@ private:
private: private:
int m_tolerance; // max distance between a track end point and a pad/via center to int m_tolerance; // max distance between a track end point and a pad/via center to
// see them connected to ut a teardrop // see them connected to ut a teardrop
bool m_applyToViaPads; // true to add a teardrop to vias and PTH pads
bool m_applyToRoundShapesOnly; // true to add a teardrop to round pads only
bool m_applyToSurfacePads; // true to add a teardrop not drilled pads (like SMD)
bool m_applyToTracks; // true to add a teardrop to connected point of 2 tracks
// having different width
BOARD* m_board; BOARD* m_board;
TEARDROP_PARAMETERS_LIST* m_prmsList; // the teardrop parameters list, from the board desing settings
std::vector<ZONE*> m_createdTdList; // list of new created teardrops std::vector<ZONE*> m_createdTdList; // list of new created teardrops
}; };