40 m_drawings( aDrawings ),
41 m_parentFootprint( aParentFootprint ),
43 m_toolMgr( aToolMgr ),
46 m_itemsList( nullptr )
52 std::vector<std::shared_ptr<CLEANUP_ITEM>>* aItemsList,
53 bool aMergeRects,
bool aDeleteRedundant,
bool aMergePads )
64 if( aDeleteRedundant )
89 case SHAPE_T::SEGMENT:
90 case SHAPE_T::RECTANGLE:
100 case SHAPE_T::BEZIER:
128 case SHAPE_T::SEGMENT:
129 case SHAPE_T::RECTANGLE:
130 case SHAPE_T::CIRCLE:
143 case SHAPE_T::BEZIER:
150 wxFAIL_MSG( wxT(
"GRAPHICS_CLEANER::areEquivalent unimplemented for " )
170 item->SetItems( shape );
179 for(
auto it2 = it + 1; it2 !=
m_drawings.end(); it2++ )
189 item->SetItems( shape2 );
204 struct SIDE_CANDIDATE
211 if( start.x > end.x || start.y > end.y )
212 std::swap( start, end );
220 std::vector<SIDE_CANDIDATE*> sides;
221 std::map<VECTOR2I, std::vector<SIDE_CANDIDATE*>> ptMap;
233 sides.emplace_back(
new SIDE_CANDIDATE( shape ) );
234 ptMap[ sides.back()->start ].push_back( sides.back() );
239 for( SIDE_CANDIDATE* side : sides )
244 SIDE_CANDIDATE*
left =
nullptr;
245 SIDE_CANDIDATE* top =
nullptr;
246 SIDE_CANDIDATE*
right =
nullptr;
247 SIDE_CANDIDATE* bottom =
nullptr;
249 auto viable = [&]( SIDE_CANDIDATE* aCandidate ) ->
bool
251 return aCandidate->shape->GetLayer() == side->shape->GetLayer()
252 && aCandidate->shape->GetWidth() == side->shape->GetWidth()
256 if( side->start.x == side->end.x )
262 for( SIDE_CANDIDATE* candidate : ptMap[
left->start ] )
264 if( candidate !=
left && viable( candidate ) )
271 else if( side->start.y == side->end.y )
277 for( SIDE_CANDIDATE* candidate : ptMap[ top->start ] )
279 if( candidate != top && viable( candidate ) )
291 for( SIDE_CANDIDATE* candidate : ptMap[ top->end ] )
293 if( candidate != top && candidate !=
left && viable( candidate ) )
300 for( SIDE_CANDIDATE* candidate : ptMap[
left->end ] )
302 if( candidate != top && candidate !=
left && viable( candidate ) )
309 if(
right && bottom &&
right->end == bottom->end )
317 item->SetItems(
left->shape, top->shape,
right->shape, bottom->shape );
324 rect->
SetShape( SHAPE_T::RECTANGLE );
327 rect->
SetEnd( bottom->end );
328 rect->
SetLayer( top->shape->GetLayer() );
329 rect->
SetStroke( top->shape->GetStroke() );
341 for( SIDE_CANDIDATE* side : sides )
348 wxCHECK_MSG(
m_parentFootprint, , wxT(
"mergePads() is FootprintEditor only" ) );
356 if( padToNetTieGroupMap[
pad->GetNumber() ] >= 0 )
361 if( !shapes.empty() )
363 std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>(
CLEANUP_MERGE_PAD );
366 item->AddItem( shape );
368 item->AddItem(
pad );
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been removed.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
void SetFlags(EDA_ITEM_FLAGS aMask)
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
const VECTOR2I & GetBezierC2() const
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
void SetFilled(bool aFlag)
int GetPointCount() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetShape(SHAPE_T aShape)
const std::vector< VECTOR2I > & GetBezierPoints() const
void SetEnd(const VECTOR2I &aEnd)
wxString SHAPE_T_asString() const
const VECTOR2I & GetBezierC1() const
void CleanupBoard(bool aDryRun, std::vector< std::shared_ptr< CLEANUP_ITEM > > *aItemsList, bool aMergeRects, bool aDeleteRedundant, bool aMergePads)
the cleanup function.
std::vector< std::shared_ptr< CLEANUP_ITEM > > * m_itemsList
FOOTPRINT * m_parentFootprint
GRAPHICS_CLEANER(DRAWINGS &aDrawings, FOOTPRINT *aParentFootprint, BOARD_COMMIT &aCommit, TOOL_MANAGER *aToolManager)
bool isNullShape(PCB_SHAPE *aShape)
bool areEquivalent(PCB_SHAPE *aShape1, PCB_SHAPE *aShape2)
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
int GetWidth() const override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStroke(const STROKE_PARAMS &aStroke) override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
@ CLEANUP_DUPLICATE_GRAPHIC
bool equivalent(SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b)
bool equivalent(const VECTOR2I &a, const VECTOR2I &b, int epsilon)
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)