2020-06-17 12:46:50 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-06-17 12:46:50 +00:00
|
|
|
*
|
|
|
|
* 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 <reporter.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <macros.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
#include <board_commit.h>
|
|
|
|
#include <cleanup_item.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2022-09-24 16:29:14 +00:00
|
|
|
#include <pad.h>
|
|
|
|
#include <footprint.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
#include <graphics_cleaner.h>
|
2023-10-17 07:27:59 +00:00
|
|
|
#include <fix_board_shape.h>
|
2022-03-02 14:18:46 +00:00
|
|
|
#include <board_design_settings.h>
|
2022-09-24 16:29:14 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pad_tool.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2024-03-25 21:37:40 +00:00
|
|
|
GRAPHICS_CLEANER::GRAPHICS_CLEANER( const DRAWINGS& aDrawings, FOOTPRINT* aParentFootprint,
|
2022-09-24 16:29:14 +00:00
|
|
|
BOARD_COMMIT& aCommit, TOOL_MANAGER* aToolMgr ) :
|
2020-06-17 12:46:50 +00:00
|
|
|
m_drawings( aDrawings ),
|
2020-11-13 15:15:52 +00:00
|
|
|
m_parentFootprint( aParentFootprint ),
|
2020-06-17 12:46:50 +00:00
|
|
|
m_commit( aCommit ),
|
2022-09-24 16:29:14 +00:00
|
|
|
m_toolMgr( aToolMgr ),
|
2020-06-17 12:46:50 +00:00
|
|
|
m_dryRun( true ),
|
2022-03-06 08:48:33 +00:00
|
|
|
m_epsilon( 0 ),
|
2023-10-23 17:48:45 +00:00
|
|
|
m_outlinesTolerance( 0 ),
|
2020-06-17 12:46:50 +00:00
|
|
|
m_itemsList( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-17 07:27:59 +00:00
|
|
|
void GRAPHICS_CLEANER::CleanupBoard( bool aDryRun,
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<std::shared_ptr<CLEANUP_ITEM>>* aItemsList,
|
2023-10-17 07:27:59 +00:00
|
|
|
bool aMergeRects, bool aDeleteRedundant, bool aMergePads,
|
|
|
|
bool aFixBoardOutlines, int aTolerance )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
|
|
|
m_dryRun = aDryRun;
|
|
|
|
m_itemsList = aItemsList;
|
2023-10-17 07:27:59 +00:00
|
|
|
m_outlinesTolerance = aTolerance;
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
m_epsilon = m_commit.GetBoard()->GetDesignSettings().m_MaxError;
|
|
|
|
|
|
|
|
// Clear the flag used to mark some shapes as deleted, in dry run:
|
2020-06-17 12:46:50 +00:00
|
|
|
for( BOARD_ITEM* drawing : m_drawings )
|
|
|
|
drawing->ClearFlags( IS_DELETED );
|
|
|
|
|
|
|
|
if( aDeleteRedundant )
|
2022-03-02 14:18:46 +00:00
|
|
|
cleanupShapes();
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2023-10-17 07:27:59 +00:00
|
|
|
if( aFixBoardOutlines )
|
|
|
|
fixBoardOutlines();
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
if( aMergeRects )
|
|
|
|
mergeRects();
|
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
if( aMergePads )
|
|
|
|
mergePads();
|
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
// Clear the flag used to mark some shapes:
|
2020-06-17 12:46:50 +00:00
|
|
|
for( BOARD_ITEM* drawing : m_drawings )
|
|
|
|
drawing->ClearFlags( IS_DELETED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
bool equivalent( const VECTOR2I& a, const VECTOR2I& b, int epsilon )
|
|
|
|
{
|
|
|
|
return abs( a.x - b.x ) < epsilon && abs( a.y - b.y ) < epsilon;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
bool GRAPHICS_CLEANER::isNullShape( PCB_SHAPE* aShape )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
switch( aShape->GetShape() )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2021-07-17 19:56:18 +00:00
|
|
|
case SHAPE_T::ARC:
|
2022-03-02 14:18:46 +00:00
|
|
|
return equivalent( aShape->GetStart(), aShape->GetEnd(), m_epsilon );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
return aShape->GetRadius() == 0;
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
|
|
|
return aShape->GetPointCount() == 0;
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2024-06-18 04:47:06 +00:00
|
|
|
aShape->RebuildBezierToSegmentsPointsList( ARC_HIGH_DEF );
|
2022-12-10 16:59:50 +00:00
|
|
|
|
|
|
|
// If the Bezier points list contains 2 points, it is equivalent to a segment
|
|
|
|
if( aShape->GetBezierPoints().size() == 2 )
|
|
|
|
return equivalent( aShape->GetStart(), aShape->GetEnd(), m_epsilon );
|
|
|
|
|
|
|
|
// If the Bezier points list contains 1 points, it is equivalent to a point
|
|
|
|
return aShape->GetBezierPoints().size() < 2;
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
default:
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( aShape->SHAPE_T_asString() );
|
2020-06-17 12:46:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
bool GRAPHICS_CLEANER::areEquivalent( PCB_SHAPE* aShape1, PCB_SHAPE* aShape2 )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
if( aShape1->GetShape() != aShape2->GetShape()
|
|
|
|
|| aShape1->GetLayer() != aShape2->GetLayer()
|
|
|
|
|| aShape1->GetWidth() != aShape2->GetWidth() )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
switch( aShape1->GetShape() )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2022-03-02 14:18:46 +00:00
|
|
|
return equivalent( aShape1->GetStart(), aShape2->GetStart(), m_epsilon )
|
|
|
|
&& equivalent( aShape1->GetEnd(), aShape2->GetEnd(), m_epsilon );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2022-03-02 14:18:46 +00:00
|
|
|
return equivalent( aShape1->GetCenter(), aShape2->GetCenter(), m_epsilon )
|
|
|
|
&& equivalent( aShape1->GetStart(), aShape2->GetStart(), m_epsilon )
|
|
|
|
&& equivalent( aShape1->GetEnd(), aShape2->GetEnd(), m_epsilon );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2020-06-17 12:46:50 +00:00
|
|
|
// TODO
|
|
|
|
return false;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2022-03-02 14:18:46 +00:00
|
|
|
return equivalent( aShape1->GetStart(), aShape2->GetStart(), m_epsilon )
|
|
|
|
&& equivalent( aShape1->GetEnd(), aShape2->GetEnd(), m_epsilon )
|
|
|
|
&& equivalent( aShape1->GetBezierC1(), aShape2->GetBezierC1(), m_epsilon )
|
|
|
|
&& equivalent( aShape1->GetBezierC2(), aShape2->GetBezierC2(), m_epsilon );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
default:
|
2022-02-04 22:44:59 +00:00
|
|
|
wxFAIL_MSG( wxT( "GRAPHICS_CLEANER::areEquivalent unimplemented for " )
|
2021-07-14 20:03:32 +00:00
|
|
|
+ aShape1->SHAPE_T_asString() );
|
2020-06-17 12:46:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
void GRAPHICS_CLEANER::cleanupShapes()
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2022-03-02 14:18:46 +00:00
|
|
|
// Remove duplicate shapes (2 superimposed identical shapes):
|
2020-06-17 12:46:50 +00:00
|
|
|
for( auto it = m_drawings.begin(); it != m_drawings.end(); it++ )
|
|
|
|
{
|
2022-03-02 14:18:46 +00:00
|
|
|
PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( *it );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
if( !shape || shape->HasFlag( IS_DELETED ) )
|
2020-06-17 12:46:50 +00:00
|
|
|
continue;
|
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
if( isNullShape( shape ) )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_NULL_GRAPHIC );
|
2022-03-02 14:18:46 +00:00
|
|
|
item->SetItems( shape );
|
2020-06-17 12:46:50 +00:00
|
|
|
m_itemsList->push_back( item );
|
|
|
|
|
2020-06-29 21:58:05 +00:00
|
|
|
if( !m_dryRun )
|
2022-03-02 14:18:46 +00:00
|
|
|
m_commit.Remove( shape );
|
2020-06-29 21:58:05 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto it2 = it + 1; it2 != m_drawings.end(); it2++ )
|
|
|
|
{
|
2022-03-02 14:18:46 +00:00
|
|
|
PCB_SHAPE* shape2 = dynamic_cast<PCB_SHAPE*>( *it2 );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
if( !shape2 || shape2->HasFlag( IS_DELETED ) )
|
2020-06-17 12:46:50 +00:00
|
|
|
continue;
|
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
if( areEquivalent( shape, shape2 ) )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_DUPLICATE_GRAPHIC );
|
2022-03-02 14:18:46 +00:00
|
|
|
item->SetItems( shape2 );
|
2020-06-17 12:46:50 +00:00
|
|
|
m_itemsList->push_back( item );
|
|
|
|
|
2022-03-02 14:18:46 +00:00
|
|
|
shape2->SetFlags(IS_DELETED );
|
2020-06-29 21:58:05 +00:00
|
|
|
|
|
|
|
if( !m_dryRun )
|
2022-03-02 14:18:46 +00:00
|
|
|
m_commit.Remove( shape2 );
|
2020-06-17 12:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-17 07:27:59 +00:00
|
|
|
void GRAPHICS_CLEANER::fixBoardOutlines()
|
|
|
|
{
|
|
|
|
if( m_dryRun )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<PCB_SHAPE*> shapeList;
|
|
|
|
std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
|
|
|
{
|
|
|
|
PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
|
|
|
|
|
|
|
|
if( !shape || !shape->IsOnLayer( Edge_Cuts ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
shapeList.push_back( shape );
|
|
|
|
|
|
|
|
if( !m_dryRun )
|
|
|
|
m_commit.Modify( shape );
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectBoardShapes( shapeList, newShapes, m_outlinesTolerance );
|
|
|
|
|
|
|
|
std::vector<PCB_SHAPE*> items_to_select;
|
|
|
|
|
|
|
|
for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
|
|
|
|
m_commit.Add( ptr.release() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
void GRAPHICS_CLEANER::mergeRects()
|
|
|
|
{
|
|
|
|
struct SIDE_CANDIDATE
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
SIDE_CANDIDATE( PCB_SHAPE* aShape ) :
|
|
|
|
start( aShape->GetStart() ),
|
|
|
|
end( aShape->GetEnd() ),
|
|
|
|
shape( aShape )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
|
|
|
if( start.x > end.x || start.y > end.y )
|
|
|
|
std::swap( start, end );
|
|
|
|
}
|
|
|
|
|
2022-01-01 18:57:44 +00:00
|
|
|
VECTOR2I start;
|
|
|
|
VECTOR2I end;
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape;
|
2020-06-17 12:46:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<SIDE_CANDIDATE*> sides;
|
2022-01-01 18:57:44 +00:00
|
|
|
std::map<VECTOR2I, std::vector<SIDE_CANDIDATE*>> ptMap;
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
// First load all the candidates into the side vector and layer maps
|
|
|
|
for( BOARD_ITEM* item : m_drawings )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2021-09-13 17:03:48 +00:00
|
|
|
if( !shape || isNullShape( shape ) || shape->GetShape() != SHAPE_T::SEGMENT )
|
2020-06-17 12:46:50 +00:00
|
|
|
continue;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
if( shape->GetStart().x == shape->GetEnd().x || shape->GetStart().y == shape->GetEnd().y )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
sides.emplace_back( new SIDE_CANDIDATE( shape ) );
|
2020-06-17 12:46:50 +00:00
|
|
|
ptMap[ sides.back()->start ].push_back( sides.back() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now go through the sides and try and match lines into rectangles
|
|
|
|
for( SIDE_CANDIDATE* side : sides )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
if( side->shape->HasFlag( IS_DELETED ) )
|
2020-06-17 12:46:50 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
SIDE_CANDIDATE* left = nullptr;
|
|
|
|
SIDE_CANDIDATE* top = nullptr;
|
|
|
|
SIDE_CANDIDATE* right = nullptr;
|
|
|
|
SIDE_CANDIDATE* bottom = nullptr;
|
|
|
|
|
|
|
|
auto viable = [&]( SIDE_CANDIDATE* aCandidate ) -> bool
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
return aCandidate->shape->GetLayer() == side->shape->GetLayer()
|
|
|
|
&& aCandidate->shape->GetWidth() == side->shape->GetWidth()
|
|
|
|
&& !aCandidate->shape->HasFlag( IS_DELETED );
|
2020-06-17 12:46:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if( side->start.x == side->end.x )
|
|
|
|
{
|
|
|
|
// We've found a possible left; see if we have a top
|
|
|
|
//
|
|
|
|
left = side;
|
|
|
|
|
|
|
|
for( SIDE_CANDIDATE* candidate : ptMap[ left->start ] )
|
|
|
|
{
|
|
|
|
if( candidate != left && viable( candidate ) )
|
|
|
|
{
|
|
|
|
top = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( side->start.y == side->end.y )
|
|
|
|
{
|
|
|
|
// We've found a possible top; see if we have a left
|
|
|
|
//
|
|
|
|
top = side;
|
|
|
|
|
|
|
|
for( SIDE_CANDIDATE* candidate : ptMap[ top->start ] )
|
|
|
|
{
|
|
|
|
if( candidate != top && viable( candidate ) )
|
|
|
|
{
|
|
|
|
left = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( top && left )
|
|
|
|
{
|
|
|
|
// See if we can fill in the other two sides
|
|
|
|
//
|
|
|
|
for( SIDE_CANDIDATE* candidate : ptMap[ top->end ] )
|
|
|
|
{
|
2021-09-13 17:03:48 +00:00
|
|
|
if( candidate != top && candidate != left && viable( candidate ) )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
|
|
|
right = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SIDE_CANDIDATE* candidate : ptMap[ left->end ] )
|
|
|
|
{
|
2021-09-13 17:03:48 +00:00
|
|
|
if( candidate != top && candidate != left && viable( candidate ) )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
|
|
|
bottom = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-30 20:01:23 +00:00
|
|
|
if( right && bottom && right->end == bottom->end )
|
2020-06-17 12:46:50 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
left->shape->SetFlags( IS_DELETED );
|
|
|
|
top->shape->SetFlags( IS_DELETED );
|
|
|
|
right->shape->SetFlags( IS_DELETED );
|
|
|
|
bottom->shape->SetFlags( IS_DELETED );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_LINES_TO_RECT );
|
2020-10-04 23:34:59 +00:00
|
|
|
item->SetItems( left->shape, top->shape, right->shape, bottom->shape );
|
2020-06-17 12:46:50 +00:00
|
|
|
m_itemsList->push_back( item );
|
|
|
|
|
|
|
|
if( !m_dryRun )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* rect = new PCB_SHAPE( m_parentFootprint );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
rect->SetShape( SHAPE_T::RECTANGLE );
|
2020-11-14 01:16:02 +00:00
|
|
|
rect->SetFilled( false );
|
2020-06-17 12:46:50 +00:00
|
|
|
rect->SetStart( top->start );
|
|
|
|
rect->SetEnd( bottom->end );
|
2020-10-04 23:34:59 +00:00
|
|
|
rect->SetLayer( top->shape->GetLayer() );
|
2021-07-17 19:56:18 +00:00
|
|
|
rect->SetStroke( top->shape->GetStroke() );
|
2020-06-17 12:46:50 +00:00
|
|
|
|
|
|
|
m_commit.Add( rect );
|
2020-10-04 23:34:59 +00:00
|
|
|
m_commit.Remove( left->shape );
|
|
|
|
m_commit.Remove( top->shape );
|
|
|
|
m_commit.Remove( right->shape );
|
|
|
|
m_commit.Remove( bottom->shape );
|
2020-06-17 12:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SIDE_CANDIDATE* side : sides )
|
|
|
|
delete side;
|
|
|
|
}
|
|
|
|
|
2022-09-24 16:29:14 +00:00
|
|
|
|
|
|
|
void GRAPHICS_CLEANER::mergePads()
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( m_parentFootprint, /*void*/, wxT( "mergePads() is FootprintEditor only" ) );
|
|
|
|
|
2022-09-25 16:23:14 +00:00
|
|
|
PAD_TOOL* padTool = m_toolMgr->GetTool<PAD_TOOL>();
|
|
|
|
std::map<wxString, int> padToNetTieGroupMap = m_parentFootprint->MapPadNumbersToNetTieGroups();
|
2022-09-24 16:29:14 +00:00
|
|
|
|
|
|
|
for( PAD* pad : m_parentFootprint->Pads() )
|
|
|
|
{
|
2022-09-25 16:23:14 +00:00
|
|
|
// Don't merge a pad that's in a net-tie pad group. (We don't care which group.)
|
|
|
|
if( padToNetTieGroupMap[ pad->GetNumber() ] >= 0 )
|
2022-09-24 16:29:14 +00:00
|
|
|
continue;
|
|
|
|
|
2023-10-13 12:51:27 +00:00
|
|
|
if( m_commit.GetStatus( m_parentFootprint ) == 0 )
|
|
|
|
m_commit.Modify( m_parentFootprint );
|
|
|
|
|
|
|
|
std::vector<PCB_SHAPE*> shapes = padTool->RecombinePad( pad, m_dryRun );
|
2022-09-24 16:29:14 +00:00
|
|
|
|
|
|
|
if( !shapes.empty() )
|
|
|
|
{
|
|
|
|
std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_MERGE_PAD );
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
for( PCB_SHAPE* shape : shapes )
|
2022-09-24 16:29:14 +00:00
|
|
|
item->AddItem( shape );
|
|
|
|
|
|
|
|
item->AddItem( pad );
|
|
|
|
|
|
|
|
m_itemsList->push_back( item );
|
|
|
|
}
|
|
|
|
}
|
2024-03-25 21:37:40 +00:00
|
|
|
}
|