41 m_drawings( aDrawings ),
42 m_parentFootprint( aParentFootprint ),
44 m_toolMgr( aToolMgr ),
47 m_outlinesTolerance( 0 ),
48 m_itemsList( nullptr )
54 std::vector<std::shared_ptr<CLEANUP_ITEM>>* aItemsList,
55 bool aMergeRects,
bool aDeleteRedundant,
bool aMergePads,
56 bool aFixBoardOutlines,
int aTolerance )
68 if( aDeleteRedundant )
71 if( aFixBoardOutlines )
96 case SHAPE_T::SEGMENT:
97 case SHAPE_T::RECTANGLE:
101 case SHAPE_T::CIRCLE:
107 case SHAPE_T::BEZIER:
135 case SHAPE_T::SEGMENT:
136 case SHAPE_T::RECTANGLE:
137 case SHAPE_T::CIRCLE:
150 case SHAPE_T::BEZIER:
157 wxFAIL_MSG( wxT(
"GRAPHICS_CLEANER::areEquivalent unimplemented for " )
177 item->SetItems( shape );
186 for(
auto it2 = it + 1; it2 !=
m_drawings.end(); it2++ )
196 item->SetItems( shape2 );
214 std::vector<PCB_SHAPE*> shapeList;
215 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
224 shapeList.push_back( shape );
232 std::vector<PCB_SHAPE*> items_to_select;
234 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
241 struct SIDE_CANDIDATE
248 if( start.x > end.x || start.y > end.y )
249 std::swap( start, end );
257 std::vector<SIDE_CANDIDATE*> sides;
258 std::map<VECTOR2I, std::vector<SIDE_CANDIDATE*>> ptMap;
270 sides.emplace_back(
new SIDE_CANDIDATE( shape ) );
271 ptMap[ sides.back()->start ].push_back( sides.back() );
276 for( SIDE_CANDIDATE* side : sides )
281 SIDE_CANDIDATE*
left =
nullptr;
282 SIDE_CANDIDATE* top =
nullptr;
283 SIDE_CANDIDATE*
right =
nullptr;
284 SIDE_CANDIDATE* bottom =
nullptr;
286 auto viable = [&]( SIDE_CANDIDATE* aCandidate ) ->
bool
288 return aCandidate->shape->GetLayer() == side->shape->GetLayer()
289 && aCandidate->shape->GetWidth() == side->shape->GetWidth()
293 if( side->start.x == side->end.x )
299 for( SIDE_CANDIDATE* candidate : ptMap[
left->start ] )
301 if( candidate !=
left && viable( candidate ) )
308 else if( side->start.y == side->end.y )
314 for( SIDE_CANDIDATE* candidate : ptMap[ top->start ] )
316 if( candidate != top && viable( candidate ) )
328 for( SIDE_CANDIDATE* candidate : ptMap[ top->end ] )
330 if( candidate != top && candidate !=
left && viable( candidate ) )
337 for( SIDE_CANDIDATE* candidate : ptMap[
left->end ] )
339 if( candidate != top && candidate !=
left && viable( candidate ) )
346 if(
right && bottom &&
right->end == bottom->end )
354 item->SetItems(
left->shape, top->shape,
right->shape, bottom->shape );
361 rect->
SetShape( SHAPE_T::RECTANGLE );
364 rect->
SetEnd( bottom->end );
365 rect->
SetLayer( top->shape->GetLayer() );
366 rect->
SetStroke( top->shape->GetStroke() );
378 for( SIDE_CANDIDATE* side : sides )
385 wxCHECK_MSG(
m_parentFootprint, , wxT(
"mergePads() is FootprintEditor only" ) );
393 if( padToNetTieGroupMap[
pad->GetNumber() ] >= 0 )
401 if( !shapes.empty() )
403 std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>(
CLEANUP_MERGE_PAD );
406 item->AddItem( shape );
408 item->AddItem(
pad );
constexpr int ARC_HIGH_DEF
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 & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
int GetStatus(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
void SetFlags(EDA_ITEM_FLAGS aMask)
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
const VECTOR2I & GetBezierC2() const
virtual void SetFilled(bool aFlag)
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
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
GRAPHICS_CLEANER(const DRAWINGS &aDrawings, FOOTPRINT *aParentFootprint, BOARD_COMMIT &aCommit, TOOL_MANAGER *aToolManager)
std::vector< std::shared_ptr< CLEANUP_ITEM > > * m_itemsList
FOOTPRINT * m_parentFootprint
void CleanupBoard(bool aDryRun, std::vector< std::shared_ptr< CLEANUP_ITEM > > *aItemsList, bool aMergeRects, bool aDeleteRedundant, bool aMergePads, bool aFixBoardOutlines, int aTolerance)
the cleanup function.
const DRAWINGS & m_drawings
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.
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
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)
void ConnectBoardShapes(std::vector< PCB_SHAPE * > &aShapeList, std::vector< std::unique_ptr< PCB_SHAPE > > &aNewShapes, int aChainingEpsilon)
Connects shapes to each other, making continious contours (adjacent shapes will have a common vertex)...
bool equivalent(const VECTOR2I &a, const VECTOR2I &b, int epsilon)
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)