Reduce public API of PCB_GENERATOR_MEANDERS.

It doesn't make a huge difference because the class is declared in
the .cpp file, but it still makes it easier to understand what is
conceptually public and what is not.
This commit is contained in:
Jeff Young 2023-10-14 13:38:25 +01:00
parent 5f5113c80a
commit 8028ea893f
1 changed files with 1250 additions and 1163 deletions

View File

@ -70,7 +70,192 @@ enum LENGTH_TUNING_MODE
};
static LENGTH_TUNING_MODE TuningFromString( const std::string& aStr )
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" ); }
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;
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 )
{
if( aStr == "single" )
return LENGTH_TUNING_MODE::SINGLE;
@ -86,7 +271,7 @@ static LENGTH_TUNING_MODE TuningFromString( const std::string& aStr )
}
static std::string TuningToString( const LENGTH_TUNING_MODE aTuning )
static std::string tuningToString( const LENGTH_TUNING_MODE aTuning )
{
switch( aTuning )
{
@ -98,7 +283,7 @@ static std::string TuningToString( const LENGTH_TUNING_MODE aTuning )
}
static LENGTH_TUNING_MODE FromPNSMode( PNS::ROUTER_MODE aRouterMode )
static LENGTH_TUNING_MODE fromPNSMode( PNS::ROUTER_MODE aRouterMode )
{
switch( aRouterMode )
{
@ -110,7 +295,7 @@ static LENGTH_TUNING_MODE FromPNSMode( PNS::ROUTER_MODE aRouterMode )
}
static PNS::MEANDER_SIDE SideFromString( const std::string& aStr )
static PNS::MEANDER_SIDE sideFromString( const std::string& aStr )
{
if( aStr == "default" )
return PNS::MEANDER_SIDE_DEFAULT;
@ -126,7 +311,7 @@ static PNS::MEANDER_SIDE SideFromString( const std::string& aStr )
}
static std::string StatusToString( const PNS::MEANDER_PLACER_BASE::TUNING_STATUS aStatus )
static std::string statusToString( const PNS::MEANDER_PLACER_BASE::TUNING_STATUS aStatus )
{
switch( aStatus )
{
@ -138,7 +323,7 @@ static std::string StatusToString( const PNS::MEANDER_PLACER_BASE::TUNING_STATUS
}
static PNS::MEANDER_PLACER_BASE::TUNING_STATUS StatusFromString( const std::string& aStr )
static PNS::MEANDER_PLACER_BASE::TUNING_STATUS statusFromString( const std::string& aStr )
{
if( aStr == "too_long" )
return PNS::MEANDER_PLACER_BASE::TOO_LONG;
@ -154,7 +339,7 @@ static PNS::MEANDER_PLACER_BASE::TUNING_STATUS StatusFromString( const std::stri
}
static std::string SideToString( const PNS::MEANDER_SIDE aValue )
static std::string sideToString( const PNS::MEANDER_SIDE aValue )
{
switch( aValue )
{
@ -174,14 +359,8 @@ static NETINFO_ITEM* getCoupledNet( PNS::ROUTER* aRouter, NETINFO_ITEM* aNet )
}
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 ) :
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 ),
@ -201,9 +380,8 @@ public:
m_initialSide = PNS::MEANDER_SIDE_DEFAULT;
}
wxString GetGeneratorType() const override { return wxS( "meanders" ); }
NETINFO_ITEM* snapToNearestTrackPoint( VECTOR2I& aP, BOARD* aBoard, NETINFO_ITEM* aNet )
static NETINFO_ITEM* snapToNearestTrackPoint( VECTOR2I& aP, BOARD* aBoard, NETINFO_ITEM* aNet )
{
SEG::ecoord minDistSq = VECTOR2I::ECOORD_MAX;
VECTOR2I closestPt = aP;
@ -236,9 +414,10 @@ public:
return nullptr;
}
bool baselineValid()
bool PCB_GENERATOR_MEANDERS::baselineValid()
{
if( m_tuningMode == DIFF_PAIR )
if( m_tuningMode == DIFF_PAIR || m_tuningMode == DIFF_PAIR_SKEW )
{
return( m_baseLine && m_baseLine->PointCount() > 1
&& m_baseLineCoupled && m_baseLineCoupled->PointCount() > 1 );
@ -249,7 +428,9 @@ public:
}
}
static PCB_GENERATOR_MEANDERS* CreateNew( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
PCB_GENERATOR_MEANDERS* PCB_GENERATOR_MEANDERS::CreateNew( GENERATOR_TOOL* aTool,
PCB_BASE_EDIT_FRAME* aFrame,
BOARD_CONNECTED_ITEM* aStartItem,
LENGTH_TUNING_MODE aMode )
{
@ -308,8 +489,8 @@ public:
return meander;
}
void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
BOARD_COMMIT* aCommit ) override
void PCB_GENERATOR_MEANDERS::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard,
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit )
{
m_removedItems.clear();
@ -328,7 +509,7 @@ public:
router->SyncWorld();
if( !baselineValid() )
InitBaseLine( router, layer, aBoard );
initBaseLines( router, layer, aBoard );
if( baselineValid() && !m_overrideCustomRules )
{
@ -374,7 +555,8 @@ public:
}
}
PNS::LINKED_ITEM* PickSegment( PNS::ROUTER* aRouter, const VECTOR2I& aWhere, int aLayer,
static PNS::LINKED_ITEM* pickSegment( PNS::ROUTER* aRouter, const VECTOR2I& aWhere, int aLayer,
VECTOR2I& aPointOut )
{
static const int candidateCount = 2;
@ -473,19 +655,47 @@ public:
return rv;
}
bool initBaseLine( PNS::ROUTER* router, int layer, BOARD* aBoard, VECTOR2I& aStart,
VECTOR2I& aEnd, NETINFO_ITEM* aNet,
std::optional<SHAPE_LINE_CHAIN>& aBaseLine )
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();
PNS::LINKED_ITEM* startItem = pickSegment( router, aStart, layer, aStartOut );
PNS::LINKED_ITEM* endItem = pickSegment( router, aEnd, layer, aEndOut );
wxASSERT( startItem );
wxASSERT( endItem );
if( !startItem || !endItem )
return std::nullopt;
PNS::LINE line = world->AssembleLine( startItem, nullptr, false, true );
SHAPE_LINE_CHAIN oldChain = line.CLine();
wxCHECK( line.ContainsLink( endItem ), std::nullopt );
wxASSERT( oldChain.PointOnEdge( aStartOut, 1 ) );
wxASSERT( oldChain.PointOnEdge( aEndOut, 1 ) );
return line;
}
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();
snapToNearestTrackPoint( aStart, aBoard, aNet );
snapToNearestTrackPoint( aEnd, aBoard, aNet );
VECTOR2I startSnapPoint, endSnapPoint;
PNS::LINKED_ITEM* startItem = PickSegment( router, aStart, layer, startSnapPoint );
PNS::LINKED_ITEM* endItem = PickSegment( router, aEnd, layer, endSnapPoint );
PNS::LINKED_ITEM* startItem = pickSegment( aRouter, aStart, aLayer, startSnapPoint );
PNS::LINKED_ITEM* endItem = pickSegment( aRouter, aEnd, aLayer, endSnapPoint );
wxASSERT( startItem );
wxASSERT( endItem );
@ -512,23 +722,26 @@ public:
return true;
}
bool InitBaseLine( PNS::ROUTER* router, int layer, BOARD* aBoard )
bool PCB_GENERATOR_MEANDERS::initBaseLines( PNS::ROUTER* aRouter, int aLayer, BOARD* aBoard )
{
m_baseLineCoupled.reset();
NETINFO_ITEM* net = snapToNearestTrackPoint( m_origin, aBoard, nullptr );
if( !initBaseLine( router, layer, aBoard, m_origin, m_end, net, m_baseLine ) )
if( !initBaseLine( aRouter, aLayer, aBoard, m_origin, m_end, net, m_baseLine ) )
return false;
// 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 )
{
if( NETINFO_ITEM* coupledNet = getCoupledNet( router, net ) )
if( NETINFO_ITEM* coupledNet = getCoupledNet( aRouter, net ) )
{
VECTOR2I coupledStart = m_origin;
VECTOR2I coupledEnd = m_end;
return initBaseLine( router, layer, aBoard, coupledStart, coupledEnd, coupledNet,
return initBaseLine( aRouter, aLayer, aBoard, coupledStart, coupledEnd, coupledNet,
m_baseLineCoupled );
}
@ -538,43 +751,43 @@ public:
return true;
}
void removeToBaseline( PNS::ROUTER* aRouter, int aLayer, SHAPE_LINE_CHAIN& baseLine )
void PCB_GENERATOR_MEANDERS::removeToBaseline( PNS::ROUTER* aRouter, int aLayer,
SHAPE_LINE_CHAIN& aBaseLine )
{
VECTOR2I startSnapPoint, endSnapPoint;
std::optional<PNS::LINE> line = getLine( baseLine.CPoint( 0 ), baseLine.CPoint( -1 ),
std::optional<PNS::LINE> pnsLine = getPNSLine( aBaseLine.CPoint( 0 ), aBaseLine.CPoint( -1 ),
aRouter, aLayer, startSnapPoint, endSnapPoint );
wxCHECK( line, /* void */ );
wxCHECK( pnsLine, /* void */ );
SHAPE_LINE_CHAIN pre;
SHAPE_LINE_CHAIN mid;
SHAPE_LINE_CHAIN post;
line->CLine().Split( startSnapPoint, endSnapPoint, pre, mid, post );
pnsLine->CLine().Split( startSnapPoint, endSnapPoint, pre, mid, post );
// LINE does not have a separate remover, as LINEs are never truly a member of the tree
for( PNS::LINKED_ITEM* li : line->Links() )
for( PNS::LINKED_ITEM* li : pnsLine->Links() )
aRouter->GetInterface()->RemoveItem( li );
aRouter->GetWorld()->Remove( *line );
aRouter->GetWorld()->Remove( *pnsLine );
SHAPE_LINE_CHAIN straightChain;
straightChain.Append( pre );
straightChain.Append( baseLine );
straightChain.Append( aBaseLine );
straightChain.Append( post );
straightChain.Simplify();
PNS::LINE straightLine( *line, straightChain );
PNS::LINE straightLine( *pnsLine, straightChain );
// LINE does not have a separate remover, as LINEs are never truly a member of the tree
aRouter->GetWorld()->Add( straightLine, false );
for( PNS::LINKED_ITEM* li : straightLine.Links() )
aRouter->GetInterface()->AddItem( li );
}
void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
BOARD_COMMIT* aCommit ) override
void PCB_GENERATOR_MEANDERS::Remove( GENERATOR_TOOL* aTool, BOARD* aBoard,
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit )
{
aTool->Router()->SyncWorld();
@ -604,11 +817,10 @@ public:
if( baselineValid() )
{
removeToBaseline( router, layer, *m_baseLine );
if( m_tuningMode == DIFF_PAIR )
{
removeToBaseline( router, layer, *m_baseLineCoupled );
}
}
std::set<BOARD_ITEM*> clearRouterRemovedItems = aTool->GetRouterCommitRemovedItems();
std::set<BOARD_ITEM*> clearRouterAddedItems = aTool->GetRouterCommitAddedItems();
@ -627,33 +839,8 @@ public:
aCommit->Push( "Remove Meander", undoFlags );
}
std::optional<PNS::LINE> getLine( const VECTOR2I& aStart, const VECTOR2I& aEnd,
PNS::ROUTER* router, int layer, VECTOR2I& aStartOut,
VECTOR2I& aEndOut )
{
PNS::NODE* world = router->GetWorld();
PNS::LINKED_ITEM* startItem = PickSegment( router, aStart, layer, aStartOut );
PNS::LINKED_ITEM* endItem = PickSegment( router, aEnd, layer, aEndOut );
wxASSERT( startItem );
wxASSERT( endItem );
if( !startItem || !endItem )
return std::nullopt;
PNS::LINE line = world->AssembleLine( startItem, nullptr, false, true );
SHAPE_LINE_CHAIN oldChain = line.CLine();
wxCHECK( line.ContainsLink( endItem ), std::nullopt );
wxASSERT( oldChain.PointOnEdge( aStartOut, 1 ) );
wxASSERT( oldChain.PointOnEdge( aEndOut, 1 ) );
return line;
}
PNS::MEANDER_SETTINGS ToMeanderSettings()
PNS::MEANDER_SETTINGS PCB_GENERATOR_MEANDERS::toMeanderSettings()
{
PNS::MEANDER_SETTINGS settings;
@ -673,7 +860,8 @@ public:
return settings;
}
void FromMeanderSettings( const PNS::MEANDER_SETTINGS& aSettings )
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;
@ -687,7 +875,8 @@ public:
m_cornerRadiusPercentage = aSettings.m_cornerRadiusPercentage;
}
PNS::ROUTER_MODE ToPNSMode()
PNS::ROUTER_MODE PCB_GENERATOR_MEANDERS::toPNSMode()
{
switch( m_tuningMode )
{
@ -698,21 +887,24 @@ public:
}
}
bool resetToBaseline( PNS::ROUTER* aRouter, int aLayer, PCB_BASE_EDIT_FRAME* aFrame,
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;
std::optional<PNS::LINE> line = getLine( aBaseLine.CPoint( 0 ), aBaseLine.CPoint( -1 ),
aRouter, aLayer, startSnapPoint, endSnapPoint );
std::optional<PNS::LINE> pnsLine = getPNSLine( aBaseLine.CPoint( 0 ),
aBaseLine.CPoint( -1 ), aRouter, aLayer,
startSnapPoint, endSnapPoint );
wxCHECK( line, false );
wxCHECK( pnsLine, false );
SHAPE_LINE_CHAIN straightChain;
{
SHAPE_LINE_CHAIN pre, mid, post;
line->CLine().Split( startSnapPoint, endSnapPoint, pre, mid, post );
pnsLine->CLine().Split( startSnapPoint, endSnapPoint, pre, mid, post );
straightChain.Append( pre );
straightChain.Append( aBaseLine );
@ -720,8 +912,7 @@ public:
straightChain.Simplify();
}
// LINE does not have a separate remover, as LINEs are never truly a member of the tree
for( PNS::LINKED_ITEM* pnsItem : line->Links() )
for( PNS::LINKED_ITEM* pnsItem : pnsLine->Links() )
{
if( BOARD_ITEM* item = pnsItem->Parent() )
{
@ -730,9 +921,9 @@ public:
}
}
world->Remove( *line );
world->Remove( *pnsLine );
PNS::LINE straightLine( *line, straightChain );
PNS::LINE straightLine( *pnsLine, straightChain );
world->Add( straightLine, false );
@ -771,8 +962,9 @@ public:
return true;
}
bool Update( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
BOARD_COMMIT* aCommit ) override
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();
@ -787,7 +979,7 @@ public:
if( !baselineValid() )
{
InitBaseLine( router, layer, aBoard );
initBaseLines( router, layer, aBoard );
}
else
{
@ -798,14 +990,14 @@ public:
}
else
{
InitBaseLine( router, layer, aBoard );
initBaseLines( router, layer, aBoard );
return false;
}
if( m_tuningMode == DIFF_PAIR
&& !resetToBaseline( router, layer, aFrame, *m_baseLineCoupled, false ) )
{
InitBaseLine( router, layer, aBoard );
initBaseLines( router, layer, aBoard );
return false;
}
}
@ -813,8 +1005,8 @@ public:
// Snap points
VECTOR2I startSnapPoint, endSnapPoint;
PNS::LINKED_ITEM* startItem = PickSegment( router, m_origin, layer, startSnapPoint );
PNS::LINKED_ITEM* endItem = PickSegment( router, m_end, layer, endSnapPoint );
PNS::LINKED_ITEM* startItem = pickSegment( router, m_origin, layer, startSnapPoint );
PNS::LINKED_ITEM* endItem = pickSegment( router, m_end, layer, endSnapPoint );
wxASSERT( startItem );
wxASSERT( endItem );
@ -822,14 +1014,14 @@ public:
if( !startItem || !endItem )
return false;
router->SetMode( ToPNSMode() );
router->SetMode( toPNSMode() );
if( !router->StartRouting( startSnapPoint, startItem, layer ) )
return false;
auto placer = static_cast<PNS::MEANDER_PLACER_BASE*>( router->Placer() );
PNS::MEANDER_SETTINGS settings = ToMeanderSettings();
PNS::MEANDER_SETTINGS settings = toMeanderSettings();
placer->UpdateSettings( settings );
router->Move( m_end, nullptr );
@ -841,9 +1033,10 @@ public:
return true;
}
void EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
BOARD_COMMIT* aCommit, const wxString& aCommitMsg = wxEmptyString,
int aCommitFlags = 0 ) override
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();
@ -895,8 +1088,9 @@ public:
}
}
void EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_EDIT_FRAME* aFrame,
BOARD_COMMIT* aCommit ) override
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 );
@ -909,7 +1103,8 @@ public:
aCommit->Revert();
}
bool MakeEditPoints( std::shared_ptr<EDIT_POINTS> points ) const override
bool PCB_GENERATOR_MEANDERS::MakeEditPoints( std::shared_ptr<EDIT_POINTS> points ) const
{
VECTOR2I centerlineOffset;
@ -944,8 +1139,9 @@ public:
return true;
}
bool UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
BOARD_COMMIT* aCommit ) override
bool PCB_GENERATOR_MEANDERS::UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
BOARD_COMMIT* aCommit )
{
VECTOR2I centerlineOffset;
@ -989,7 +1185,8 @@ public:
return true;
}
bool UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints ) override
bool PCB_GENERATOR_MEANDERS::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints )
{
VECTOR2I centerlineOffset;
@ -1014,15 +1211,16 @@ public:
aEditPoints->Point( 2 ).SetPosition( base.A + widthHandleOffset );
VECTOR2I spacingHandleOffset =
widthHandleOffset + ( base.B - base.A ).Resize( KiROUND( m_spacing * 1.5 ) );
VECTOR2I spacingHandleOffset = widthHandleOffset
+ ( base.B - base.A ).Resize( KiROUND( m_spacing * 1.5 ) );
aEditPoints->Point( 3 ).SetPosition( base.A + spacingHandleOffset );
return true;
}
SHAPE_LINE_CHAIN GetRectShape() const
SHAPE_LINE_CHAIN PCB_GENERATOR_MEANDERS::getRectShape() const
{
SHAPE_LINE_CHAIN chain;
@ -1074,42 +1272,8 @@ public:
return chain;
}
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 swapData( BOARD_ITEM* aImage ) override
{
wxASSERT( aImage->Type() == PCB_GENERATOR_T );
std::swap( *this, *static_cast<PCB_GENERATOR_MEANDERS*>( aImage ) );
}
void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override final
void PCB_GENERATOR_MEANDERS::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
{
if( !IsSelected() )
return;
@ -1139,7 +1303,7 @@ public:
}
}
SHAPE_LINE_CHAIN chain = GetRectShape();
SHAPE_LINE_CHAIN chain = getRectShape();
for( int i = 0; i < chain.SegmentCount(); i++ )
{
@ -1149,63 +1313,13 @@ public:
}
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
const STRING_ANY_MAP PCB_GENERATOR_MEANDERS::GetProperties() const
{
STRING_ANY_MAP props = PCB_GENERATOR::GetProperties();
props.set( "tuning_mode", TuningToString( m_tuningMode ) );
props.set( "initial_side", SideToString( m_initialSide ) );
props.set( "last_status", StatusToString( m_tuningStatus ) );
props.set( "tuning_mode", tuningToString( m_tuningMode ) );
props.set( "initial_side", sideToString( m_initialSide ) );
props.set( "last_status", statusToString( m_tuningStatus ) );
props.set( "end", m_end );
props.set( "corner_radius_percent", m_cornerRadiusPercentage );
@ -1230,21 +1344,22 @@ public:
return props;
}
void SetProperties( const STRING_ANY_MAP& aProps ) override
void PCB_GENERATOR_MEANDERS::SetProperties( const STRING_ANY_MAP& aProps )
{
PCB_GENERATOR::SetProperties( aProps );
wxString tuningMode;
aProps.get_to( "tuning_mode", tuningMode );
m_tuningMode = TuningFromString( tuningMode.utf8_string() );
m_tuningMode = tuningFromString( tuningMode.utf8_string() );
wxString side;
aProps.get_to( "initial_side", side );
m_initialSide = SideFromString( side.utf8_string() );
m_initialSide = sideFromString( side.utf8_string() );
wxString status;
aProps.get_to( "last_status", status );
m_tuningStatus = StatusFromString( status.utf8_string() );
m_tuningStatus = statusFromString( status.utf8_string() );
aProps.get_to( "end", m_end );
aProps.get_to( "corner_radius_percent", m_cornerRadiusPercentage );
@ -1268,9 +1383,10 @@ public:
m_baseLineCoupled = *baseLineCoupled;
}
void ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame ) override
void PCB_GENERATOR_MEANDERS::ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame )
{
PNS::MEANDER_SETTINGS settings = ToMeanderSettings();
PNS::MEANDER_SETTINGS settings = toMeanderSettings();
DRC_CONSTRAINT constraint;
if( !m_items.empty() )
@ -1284,24 +1400,24 @@ public:
settings.m_targetLength = constraint.GetValue().Opt();
}
DIALOG_MEANDER_PROPERTIES dlg( aEditFrame, settings, ToPNSMode(), constraint );
DIALOG_MEANDER_PROPERTIES dlg( aEditFrame, settings, toPNSMode(), constraint );
if( dlg.ShowModal() == wxID_OK )
{
BOARD_COMMIT commit( aEditFrame );
commit.Modify( this );
FromMeanderSettings( settings );
fromMeanderSettings( settings );
commit.Push( _( "Edit Meander Properties" ) );
}
aEditFrame->GetToolManager()->PostAction<PCB_GENERATOR*>( PCB_ACTIONS::regenerateItem,
this );
aEditFrame->GetToolManager()->PostAction<PCB_GENERATOR*>( PCB_ACTIONS::regenerateItem, this );
}
void UpdateStatus( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
STATUS_TEXT_POPUP* aPopup ) override
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() );
@ -1343,35 +1459,6 @@ public:
}
}
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;
};
const wxString PCB_GENERATOR_MEANDERS::DISPLAY_NAME = _HKI( "Meanders" );
const wxString PCB_GENERATOR_MEANDERS::GENERATOR_TYPE = wxS( "meanders" );
@ -1395,7 +1482,7 @@ int DRAWING_TOOL::PlaceMeander( const TOOL_EVENT& aEvent )
m_frame->PushTool( aEvent );
Activate();
LENGTH_TUNING_MODE mode = FromPNSMode( aEvent.Parameter<PNS::ROUTER_MODE>() );
LENGTH_TUNING_MODE mode = fromPNSMode( aEvent.Parameter<PNS::ROUTER_MODE>() );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
BOARD* board = m_frame->GetBoard();
PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();