Re-factor boundary/courtyard checker error handling.

ADDED Footprint Checker dialog to display the results in.

Fixes https://gitlab.com/kicad/code/kicad/issues/6446
This commit is contained in:
Jeff Young 2020-11-21 20:42:27 +00:00
parent 22bbe9618e
commit 1391774f64
28 changed files with 855 additions and 184 deletions

View File

@ -452,9 +452,8 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR
extern bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
unsigned int aTolerance, wxString* aErrorText,
std::vector<wxPoint>* aDiscontinuities = nullptr,
std::vector<wxPoint>* aIntersections = nullptr );
int aTolerance,
OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );
bool BOARD_ADAPTER::createBoardPolygon( wxString* aErrorMsg )
@ -465,18 +464,28 @@ bool BOARD_ADAPTER::createBoardPolygon( wxString* aErrorMsg )
if( m_board->IsFootprintHolder() )
{
if( !m_board->GetFirstFootprint() )
{
if( aErrorMsg )
*aErrorMsg = _( "No footprint loaded." );
return false;
}
success = BuildFootprintPolygonOutlines( m_board, m_board_poly,
m_board->GetDesignSettings().m_MaxError, nullptr );
m_board->GetDesignSettings().m_MaxError );
// Make polygon strictly simple to avoid issues (especially in 3D viewer)
m_board_poly.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
if( !success && aErrorMsg )
*aErrorMsg = _( "Footprint outline is malformed. Run DRC for a full analysis." );
{
*aErrorMsg = _( "Footprint outline is malformed. Run Footprint Checker for a "
"full analysis." );
}
}
else
{
success = m_board->GetBoardPolygonOutlines( m_board_poly );
if( !success && aErrorMsg )

View File

@ -439,6 +439,9 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
return;
}
if( !m_rcItemsProvider )
return;
int lastGood = -1;
bool found = false;

View File

@ -149,7 +149,9 @@ void SYMBOL_EDIT_FRAME::ReCreateMenuBar()
ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool );
inspectMenu->Add( EE_ACTIONS::showDatasheet );
inspectMenu->Add( EE_ACTIONS::runERC );
inspectMenu->AppendSeparator();
inspectMenu->Add( EE_ACTIONS::checkSymbol );
//-- Preferences menu -----------------------------------------------

View File

@ -118,7 +118,7 @@ void SYMBOL_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->Add( EE_ACTIONS::showDatasheet );
m_mainToolBar->Add( EE_ACTIONS::runERC );
m_mainToolBar->Add( EE_ACTIONS::checkSymbol );
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->Add( EE_ACTIONS::showDeMorganStandard, ACTION_TOOLBAR::TOGGLE );

View File

@ -45,6 +45,11 @@ TOOL_ACTION EE_ACTIONS::runERC( "eeschema.InspectionTool.runERC",
_( "Electrical Rules Checker" ), _( "Perform electrical rules check" ),
erc_xpm );
TOOL_ACTION EE_ACTIONS::checkSymbol( "eeschema.InspectionTool.checkSymbol",
AS_GLOBAL, 0, "",
_( "Symbol Checker" ), _( "Show the symbol checker window" ),
erc_xpm );
TOOL_ACTION EE_ACTIONS::runSimulation( "eeschema.EditorControl.runSimulation",
AS_GLOBAL, 0, "",
_( "Simulator..." ), _( "Simulate circuit in SPICE" ),

View File

@ -153,6 +153,7 @@ public:
static TOOL_ACTION showBusManager;
static TOOL_ACTION schematicSetup;
static TOOL_ACTION editPageNumber;
static TOOL_ACTION checkSymbol;
static TOOL_ACTION rescueSymbols;
static TOOL_ACTION remapSymbols;

View File

@ -82,11 +82,7 @@ void EE_INSPECTION_TOOL::Reset( RESET_REASON aReason )
int EE_INSPECTION_TOOL::RunERC( const TOOL_EVENT& aEvent )
{
if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) )
{
checkPart( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurPart() );
}
else if( m_frame->IsType( FRAME_SCH ) )
if( m_frame->IsType( FRAME_SCH ) )
{
if( m_ercDialog )
{
@ -135,10 +131,12 @@ bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst )
}
void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
int EE_INSPECTION_TOOL::CheckSymbol( const TOOL_EVENT& aEvent )
{
if( !aPart )
return;
LIB_PART* part = static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurPart();
if( !part )
return 0;
wxString msg;
const int min_grid_size = 25;
@ -146,12 +144,12 @@ void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
const int clamped_grid_size = ( grid_size < min_grid_size ) ? min_grid_size : grid_size;
LIB_PINS pinList;
aPart->GetPins( pinList );
part->GetPins( pinList );
if( pinList.empty() )
{
DisplayInfoMessage( m_frame, _( "No pins!" ) );
return;
return 0;
}
// Sort pins by pin num, so 2 duplicate pins
@ -176,9 +174,9 @@ void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
dup_error++;
if( aPart->HasConversion() && next->GetConvert() )
if( part->HasConversion() && next->GetConvert() )
{
if( aPart->GetUnitCount() <= 1 )
if( part->GetUnitCount() <= 1 )
{
msg = wxString::Format( _( "<b>Duplicate pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>"
" conflicts with pin %s \"%s\" at location <b>(%.3f, %.3f)</b> of converted" ),
@ -206,7 +204,7 @@ void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
}
else
{
if( aPart->GetUnitCount() <= 1 )
if( part->GetUnitCount() <= 1 )
{
msg = wxString::Format( _( "<b>Duplicate pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>"
" conflicts with pin %s \"%s\" at location <b>(%.3f, %.3f)</b>" ),
@ -250,9 +248,9 @@ void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
// "pin" is off grid here.
offgrid_error++;
if( aPart->HasConversion() && pin->GetConvert() )
if( part->HasConversion() && pin->GetConvert() )
{
if( aPart->GetUnitCount() <= 1 )
if( part->GetUnitCount() <= 1 )
{
msg = wxString::Format( _( "<b>Off grid pin %s</b> \"%s\" at location "
"<b>(%.3f, %.3f)</b> of converted.<br>" ),
@ -272,7 +270,7 @@ void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
}
else
{
if( aPart->GetUnitCount() <= 1 )
if( part->GetUnitCount() <= 1 )
{
msg = wxString::Format( _( "<b>Off grid pin %s</b> \"%s\" at location "
"<b>(%.3f, %.3f)</b>.<br>" ),
@ -312,6 +310,8 @@ void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
error_display.m_htmlWindow->SetPage( outmsg );
error_display.ShowModal();
}
return 0;
}
@ -400,6 +400,7 @@ int EE_INSPECTION_TOOL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
void EE_INSPECTION_TOOL::setTransitions()
{
Go( &EE_INSPECTION_TOOL::RunERC, EE_ACTIONS::runERC.MakeEvent() );
Go( &EE_INSPECTION_TOOL::CheckSymbol, EE_ACTIONS::checkSymbol.MakeEvent() );
Go( &EE_INSPECTION_TOOL::RunSimulation, EE_ACTIONS::runSimulation.MakeEvent() );
Go( &EE_INSPECTION_TOOL::ShowDatasheet, EE_ACTIONS::showDatasheet.MakeEvent() );

View File

@ -49,6 +49,8 @@ public:
int RunERC( const TOOL_EVENT& aEvent );
void DestroyERCDialog();
int CheckSymbol( const TOOL_EVENT& aEvent );
int RunSimulation( const TOOL_EVENT& aEvent );
int ShowDatasheet( const TOOL_EVENT& aEvent );
@ -56,8 +58,6 @@ public:
int UpdateMessagePanel( const TOOL_EVENT& aEvent );
private:
void checkPart( LIB_PART* aPart );
///> @copydoc TOOL_INTERACTIVE::setTransitions();
void setTransitions() override;

View File

@ -63,6 +63,8 @@ set( PCBNEW_DIALOGS
dialogs/dialog_dimension_properties_base.cpp
dialogs/dialog_drc.cpp
dialogs/dialog_drc_base.cpp
dialogs/dialog_footprint_checker.cpp
dialogs/dialog_footprint_checker_base.cpp
dialogs/dialog_footprint_properties.cpp
dialogs/dialog_footprint_properties_base.cpp
dialogs/dialog_edit_footprint_for_fp_editor.cpp

View File

@ -1842,12 +1842,10 @@ bool BOARD::NormalizeAreaPolygon( PICKED_ITEMS_LIST * aNewZonesList, ZONE* aCurr
}
bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
std::vector<wxPoint>* aDiscontinuities,
std::vector<wxPoint>* aIntersections )
bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, OUTLINE_ERROR_HANDLER* aErrorHandler )
{
bool success = BuildBoardPolygonOutlines( this, aOutlines, GetDesignSettings().m_MaxError,
aDiscontinuities, aIntersections );
aErrorHandler );
// Make polygon strictly simple to avoid issues (especially in 3D viewer)
aOutlines.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );

View File

@ -588,16 +588,12 @@ public:
* Any closed outline inside the main outline is a hole
* All contours should be closed, i.e. have valid vertices to build a closed polygon
* @param aOutlines The SHAPE_POLY_SET to fill in with outlines/holes.
* @param aDiscontinuities = an optional array of wxPoint giving the locations of
* discontinuities in the outline
* @param aIntersections = an optional array of wxPoint giving the locations of self-
* intersections in the outline
* @param aErrorHandler = an optional DRC_ITEM error handler
*
* @return true if success, false if a contour is not valid
*/
bool GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
std::vector<wxPoint>* aDiscontinuities = nullptr,
std::vector<wxPoint>* aIntersections = nullptr );
OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );
/**
* Build a set of polygons which are the outlines of copper items (pads, tracks, vias, texts,

View File

@ -23,12 +23,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file convert_drawsegment_list_to_polygon.cpp
* @brief functions to convert a shape built with DRAWSEGMENTS to a polygon.
* expecting the shape describes shape similar to a polygon
*/
#include <trigo.h>
#include <macros.h>
@ -192,14 +186,10 @@ static PCB_SHAPE* findNext( PCB_SHAPE* aShape, const wxPoint& aPoint,
* @param aSegList the initial list of drawsegments (only lines, circles and arcs).
* @param aPolygons will contain the complex polygon.
* @param aTolerance is the max error distance when polygonizing a curve (internal units)
* @param aDiscontinuities = an optional array of wxPoint giving the locations of
* discontinuities in the outline
* @param aIntersections = an optional array of wxPoint giving the locations of self-
* intersections in the outline
* @param aErrorHandler = an optional error handler
*/
bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET& aPolygons,
int aTolerance, std::vector<wxPoint>* aDiscontinuities,
std::vector<wxPoint>* aIntersections )
int aTolerance, OUTLINE_ERROR_HANDLER* aErrorHandler )
{
if( aSegList.size() == 0 )
return true;
@ -331,6 +321,15 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
}
}
std::map<std::pair<VECTOR2I, VECTOR2I>, PCB_SHAPE*> segOwners;
auto fetchOwner =
[&]( const SEG& seg ) -> PCB_SHAPE*
{
auto it = segOwners.find( std::make_pair( seg.A, seg.B ) );
return it == segOwners.end() ? nullptr : it->second;
};
// Grab the left most point, assume its on the board's perimeter, and see if we
// can put enough graphics together by matching endpoints to formulate a cohesive
// polygon.
@ -370,6 +369,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
}
aPolygons.NewOutline();
bool first = true;
for( auto it = graphic->GetPolyShape().CIterate( 0 ); it; it++ )
{
@ -377,6 +377,13 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
RotatePoint( pt, orientation );
pt += offset;
aPolygons.Append( pt );
if( first )
first = false;
else
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = (wxPoint) pt;
}
}
else
@ -411,6 +418,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
nextPt = graphic->GetStart();
aPolygons.Append( nextPt );
segOwners[ std::make_pair( prevPt, nextPt ) ] = graphic;
prevPt = nextPt;
}
break;
@ -442,11 +450,13 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
RotatePoint( &pt, pcenter, rotation );
aPolygons.Append( pt );
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = pt;
}
// Append the last arc end point
aPolygons.Append( pend );
segOwners[ std::make_pair( prevPt, pend ) ] = graphic;
prevPt = pend;
}
break;
@ -463,7 +473,9 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
// very close to it.
if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) )
{
nextPt = graphic->GetEnd();
}
else
{
nextPt = graphic->GetStart();
@ -473,12 +485,21 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
if( reverse )
{
for( int jj = graphic->GetBezierPoints().size()-1; jj >= 0; jj-- )
aPolygons.Append( graphic->GetBezierPoints()[jj] );
{
const wxPoint& pt = graphic->GetBezierPoints()[jj];
aPolygons.Append( pt );
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = pt;
}
}
else
{
for( size_t jj = 0; jj < graphic->GetBezierPoints().size(); jj++ )
aPolygons.Append( graphic->GetBezierPoints()[jj] );
for( const wxPoint& pt : graphic->GetBezierPoints() )
{
aPolygons.Append( pt );
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = pt;
}
}
prevPt = nextPt;
@ -493,10 +514,11 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
// Get next closest segment.
graphic = findNext( graphic, prevPt, aSegList, aTolerance );
PCB_SHAPE* nextGraphic = findNext( graphic, prevPt, aSegList, aTolerance );
if( graphic && !( graphic->GetFlags() & SKIP_STRUCT ) )
if( nextGraphic && !( nextGraphic->GetFlags() & SKIP_STRUCT ) )
{
graphic = nextGraphic;
graphic->SetFlags( SKIP_STRUCT );
startCandidates.erase( graphic );
continue;
@ -509,15 +531,15 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
polygonComplete = true;
break;
}
else if( graphic ) // encountered already-used segment, but not at the start
else if( nextGraphic ) // encountered already-used segment, but not at the start
{
polygonComplete = false;
break;
}
else // encountered discontinuity
{
if( aDiscontinuities )
aDiscontinuities->emplace_back( prevPt );
if( aErrorHandler )
(*aErrorHandler)( _( "(not a closed shape)" ), graphic, nullptr, prevPt );
polygonComplete = false;
break;
@ -530,6 +552,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
while( startCandidates.size() )
{
int hole = aPolygons.NewHole();
bool firstPt = true;
holeNum++;
graphic = (PCB_SHAPE*) *startCandidates.begin();
@ -551,11 +574,18 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
for( auto it = graphic->GetPolyShape().CIterate(); it; it++ )
{
VECTOR2I val = *it;
RotatePoint( val, orientation );
val += offset;
VECTOR2I pt = *it;
RotatePoint( pt, orientation );
pt += offset;
aPolygons.Append( val, -1, hole );
aPolygons.Append( pt, -1, hole );
if( firstPt )
firstPt = false;
else
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = (wxPoint) pt;
}
}
else if( graphic->GetShape() == S_CIRCLE )
@ -576,6 +606,13 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
nextPt = start;
RotatePoint( &nextPt.x, &nextPt.y, center.x, center.y, rotation );
aPolygons.Append( nextPt, -1, hole );
if( firstPt )
firstPt = false;
else
segOwners[ std::make_pair( prevPt, nextPt ) ] = graphic;
prevPt = nextPt;
}
}
else if( graphic->GetShape() == S_RECT )
@ -583,7 +620,16 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
std::vector<wxPoint> pts = graphic->GetRectCorners();
for( const wxPoint& pt : pts )
{
aPolygons.Append( pt, -1, hole );
if( firstPt )
firstPt = false;
else
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = (wxPoint) pt;
}
}
else
{
@ -612,8 +658,9 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
else
nextPt = graphic->GetStart();
aPolygons.Append( nextPt, -1, hole );
segOwners[ std::make_pair( prevPt, nextPt ) ] = graphic;
prevPt = nextPt;
aPolygons.Append( prevPt, -1, hole );
}
break;
@ -644,11 +691,13 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
RotatePoint( &pt, pcenter, rotation );
aPolygons.Append( pt, -1, hole );
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = pt;
}
// Append the last arc end point
aPolygons.Append( pend, -1, hole );
segOwners[ std::make_pair( prevPt, pend ) ] = graphic;
prevPt = pend;
}
break;
@ -666,7 +715,9 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
// very close to it.
if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) )
{
nextPt = graphic->GetEnd();
}
else
{
nextPt = graphic->GetStart();
@ -676,12 +727,21 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
if( reverse )
{
for( int jj = graphic->GetBezierPoints().size()-1; jj >= 0; jj-- )
aPolygons.Append( graphic->GetBezierPoints()[jj], -1, hole );
{
const wxPoint& pt = graphic->GetBezierPoints()[jj];
aPolygons.Append( pt, -1, hole );
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = pt;
}
}
else
{
for( const wxPoint& pt : graphic->GetBezierPoints() )
{
aPolygons.Append( pt, -1, hole );
segOwners[ std::make_pair( prevPt, pt ) ] = graphic;
prevPt = pt;
}
}
prevPt = nextPt;
@ -697,10 +757,11 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
// Get next closest segment.
graphic = findNext( graphic, prevPt, aSegList, aTolerance );
PCB_SHAPE* nextGraphic = findNext( graphic, prevPt, aSegList, aTolerance );
if( graphic && !( graphic->GetFlags() & SKIP_STRUCT ) )
if( nextGraphic && !( nextGraphic->GetFlags() & SKIP_STRUCT ) )
{
graphic = nextGraphic;
graphic->SetFlags( SKIP_STRUCT );
startCandidates.erase( graphic );
continue;
@ -712,15 +773,15 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
{
break;
}
else if( graphic ) // encountered already-used segment, but not at the start
else if( nextGraphic ) // encountered already-used segment, but not at the start
{
polygonComplete = false;
break;
}
else // encountered discontinuity
{
if( aDiscontinuities )
aDiscontinuities->emplace_back( prevPt );
if( aErrorHandler )
(*aErrorHandler)( _( "(not a closed shape)" ), graphic, nullptr, prevPt );
polygonComplete = false;
break;
@ -743,21 +804,27 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
for( ++seg2; seg2; seg2++ )
{
// Check for exact overlapping segments. This is not viewed
// as an intersection below
if( *seg1 == *seg2 ||
( ( *seg1 ).A == ( *seg2 ).B && ( *seg1 ).B == ( *seg2 ).A ) )
// Check for exact overlapping segments.
if( *seg1 == *seg2 || ( ( *seg1 ).A == ( *seg2 ).B && ( *seg1 ).B == ( *seg2 ).A ) )
{
if( aIntersections )
aIntersections->emplace_back( ( *seg1 ).A.x, ( *seg1 ).A.y );
if( aErrorHandler )
{
BOARD_ITEM* a = fetchOwner( *seg1 );
BOARD_ITEM* b = fetchOwner( *seg2 );
(*aErrorHandler)( _( "(self-intersecting)" ), a, b, (wxPoint) ( *seg1 ).A );
}
selfIntersecting = true;
}
if( boost::optional<VECTOR2I> pt = seg1.Get().Intersect( seg2.Get(), true ) )
{
if( aIntersections )
aIntersections->emplace_back( (wxPoint) pt.get() );
if( aErrorHandler )
{
BOARD_ITEM* a = fetchOwner( *seg1 );
BOARD_ITEM* b = fetchOwner( *seg2 );
(*aErrorHandler)( _( "(self-intersecting)" ), a, b, (wxPoint) pt.get() );
}
selfIntersecting = true;
}
@ -767,6 +834,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
return !selfIntersecting;
}
#include <board.h>
#include <collectors.h>
@ -775,8 +843,7 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
* All contours should be closed, i.e. valid closed polygon vertices
*/
bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aTolerance,
std::vector<wxPoint>* aDiscontinuities,
std::vector<wxPoint>* aIntersections )
OUTLINE_ERROR_HANDLER* aErrorHandler )
{
PCB_TYPE_COLLECTOR items;
bool success = false;
@ -796,8 +863,7 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aT
if( segList.size() )
{
success = ConvertOutlineToPolygon( segList, aOutlines, aTolerance, aDiscontinuities,
aIntersections );
success = ConvertOutlineToPolygon( segList, aOutlines, aTolerance, aErrorHandler );
}
if( !success || !aOutlines.OutlineCount() )
@ -989,10 +1055,9 @@ int findEndSegments( SHAPE_LINE_CHAIN& aChain, SEG& aStartSeg, SEG& aEndSeg )
* * If copper is located outside a closed outline, then that outline will be treated
* as a hole, and the outer edge will be formed using the bounding box.
*/
bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
unsigned int aTolerance, wxString* aErrorText,
std::vector<wxPoint>* aDiscontinuities,
std::vector<wxPoint>* aIntersections )
bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aTolerance,
OUTLINE_ERROR_HANDLER* aErrorHandler )
{
PCB_TYPE_COLLECTOR items;
SHAPE_POLY_SET outlines;
@ -1010,8 +1075,7 @@ bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
segList.push_back( static_cast<PCB_SHAPE*>( items[ii] ) );
}
bool success = ConvertOutlineToPolygon( segList, outlines, aTolerance, aDiscontinuities,
aIntersections );
bool success = ConvertOutlineToPolygon( segList, outlines, aTolerance, aErrorHandler );
FOOTPRINT* footprint = aBoard->GetFirstFootprint();
@ -1019,10 +1083,6 @@ bool BuildFootprintPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
if( !footprint )
{
wxLogTrace( traceBoardOutline, "No footprint found on board" );
if( aErrorText )
*aErrorText = _( "No footprint loaded" );
return false;
}

View File

@ -34,6 +34,10 @@ class SHAPE_POLY_SET;
class wxString;
class wxPoint;
typedef
const std::function<void( const wxString& msg, BOARD_ITEM* itemA, BOARD_ITEM* itemB,
const wxPoint& pt )> OUTLINE_ERROR_HANDLER;
/**
* Function ConvertOutlineToPolygon
* build a polygon (with holes) from a PCB_SHAPE list, which is expected to be
@ -42,14 +46,10 @@ class wxPoint;
* @param aSegList the initial list of drawsegments (only lines, circles and arcs).
* @param aPolygons will contain the complex polygon.
* @param aTolerance is the max error distance when polygonizing a curve (internal units)
* @param aDiscontinuities = an optional array of wxPoint giving the locations of
* discontinuities in the outline
* @param aIntersections = an optional array of wxPoint giving the locations of self-
* intersections in the outline
* @param aErrorHandler = an optional error handler
*/
bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET& aPolygons,
int aTolerance, std::vector<wxPoint>* aDiscontinuities = nullptr,
std::vector<wxPoint>* aIntersections = nullptr );
int aTolerance, OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );
/**
@ -60,6 +60,5 @@ bool ConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aSegList, SHAPE_POLY_SET&
* return true if success, false if a contour is not valid
*/
extern bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, int aTolerance,
std::vector<wxPoint>* aDiscontinuities = nullptr,
std::vector<wxPoint>* aIntersections = nullptr );
OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );

View File

@ -0,0 +1,186 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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 <wx/wx.h>
#include <dialog_footprint_checker.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <pcb_marker.h>
#include <drc/drc_results_provider.h>
#include <footprint_edit_frame.h>
#include <convert_drawsegment_list_to_polygon.h>
#include <tools/footprint_editor_tools.h>
DIALOG_FOOTPRINT_CHECKER::DIALOG_FOOTPRINT_CHECKER( FOOTPRINT_EDIT_FRAME* aParent ) :
DIALOG_FOOTPRINT_CHECKER_BASE( aParent ),
m_frame( aParent )
{
m_markersTreeModel = new RC_TREE_MODEL( m_frame, m_markersDataView );
m_markersDataView->AssociateModel( m_markersTreeModel );
m_markersTreeModel->SetSeverities( -1 );
// We use a sdbSizer to get platform-dependent ordering of the action buttons, but
// that requires us to correct the button labels here.
m_sdbSizerOK->SetLabel( _( "Run Checks" ) );
m_sdbSizerCancel->SetLabel( _( "Close" ) );
m_sdbSizerOK->SetDefault();
GetSizer()->SetSizeHints(this);
Centre();
}
DIALOG_FOOTPRINT_CHECKER::~DIALOG_FOOTPRINT_CHECKER()
{
m_markersTreeModel->DecRef();
}
bool DIALOG_FOOTPRINT_CHECKER::TransferDataToWindow()
{
runChecks();
return true;
}
bool DIALOG_FOOTPRINT_CHECKER::TransferDataFromWindow()
{
return true;
}
void DIALOG_FOOTPRINT_CHECKER::runChecks()
{
BOARD* board = m_frame->GetBoard();
FOOTPRINT* footprint = board->GetFirstFootprint();
wxString msg;
deleteAllMarkers();
if( !footprint )
{
msg = _( "No footprint loaded." );
return;
}
OUTLINE_ERROR_HANDLER errorHandler =
[&]( const wxString& msg, BOARD_ITEM* itemA, BOARD_ITEM* itemB, const wxPoint& pt )
{
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD );
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
drcItem->SetItems( itemA, itemB );
PCB_MARKER* marker = new PCB_MARKER( drcItem, pt );
board->Add( marker );
m_frame->GetCanvas()->GetView()->Add( marker );
};
footprint->BuildPolyCourtyards( &errorHandler );
SetMarkersProvider( new BOARD_DRC_ITEMS_PROVIDER( m_frame->GetBoard() ) );
WINDOW_THAWER thawer( m_frame );
m_frame->GetCanvas()->Refresh();
}
void DIALOG_FOOTPRINT_CHECKER::SetMarkersProvider( RC_ITEMS_PROVIDER* aProvider )
{
m_markersTreeModel->SetProvider( aProvider );
}
void DIALOG_FOOTPRINT_CHECKER::OnRunChecksClick( wxCommandEvent& aEvent )
{
runChecks();
}
void DIALOG_FOOTPRINT_CHECKER::OnCancelClick( wxCommandEvent& aEvent )
{
m_frame->FocusOnItem( nullptr );
SetReturnCode( wxID_CANCEL );
// Leave the tool to destroy (or not) the dialog
FOOTPRINT_EDITOR_TOOLS* tool = m_frame->GetToolManager()->GetTool<FOOTPRINT_EDITOR_TOOLS>();
tool->DestroyCheckerDialog();
}
void DIALOG_FOOTPRINT_CHECKER::OnClose( wxCloseEvent& aEvent )
{
wxCommandEvent dummy;
OnCancelClick( dummy );
}
void DIALOG_FOOTPRINT_CHECKER::OnSelectItem( wxDataViewEvent& aEvent )
{
const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
BOARD_ITEM* item = m_frame->GetBoard()->GetItem( itemID );
WINDOW_THAWER thawer( m_frame );
m_frame->FocusOnItem( item );
m_frame->GetCanvas()->Refresh();
aEvent.Skip();
}
void DIALOG_FOOTPRINT_CHECKER::OnLeftDClickItem( wxMouseEvent& event )
{
event.Skip();
if( m_markersDataView->GetCurrentItem().IsOk() )
{
if( !IsModal() )
Show( false );
}
}
void DIALOG_FOOTPRINT_CHECKER::OnDeleteAllClick( wxCommandEvent& event )
{
deleteAllMarkers();
WINDOW_THAWER thawer( m_frame );
m_frame->GetCanvas()->Refresh();
}
void DIALOG_FOOTPRINT_CHECKER::deleteAllMarkers()
{
// Clear current selection list to avoid selection of deleted items
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
m_markersTreeModel->DeleteItems( false, true, true );
}

View File

@ -0,0 +1,60 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2010-2014 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
*/
#ifndef DIALOG_FOOTPRINT_CHECKER_H
#define DIALOG_FOOTPRINT_CHECKER_H
#include <dialog_footprint_checker_base.h>
#include <rc_item.h>
class FOOTPRINT_EDIT_FRAME;
class DIALOG_FOOTPRINT_CHECKER: public DIALOG_FOOTPRINT_CHECKER_BASE
{
FOOTPRINT_EDIT_FRAME* m_frame;
RC_TREE_MODEL* m_markersTreeModel;
void runChecks();
void deleteAllMarkers();
void OnRunChecksClick( wxCommandEvent& aEvent ) override;
void OnCancelClick( wxCommandEvent& aEvent ) override;
void OnClose( wxCloseEvent& event ) override;
void OnSelectItem( wxDataViewEvent& event ) override;
void OnLeftDClickItem( wxMouseEvent& event ) override;
void OnDeleteAllClick( wxCommandEvent& event ) override;
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
public:
DIALOG_FOOTPRINT_CHECKER( FOOTPRINT_EDIT_FRAME* aParent );
~DIALOG_FOOTPRINT_CHECKER();
void SetMarkersProvider( RC_ITEMS_PROVIDER* aProvider );
};
#endif // DIALOG_FOOTPRINT_CHECKER_H

View File

@ -0,0 +1,73 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_footprint_checker_base.h"
///////////////////////////////////////////////////////////////////////////
DIALOG_FOOTPRINT_CHECKER_BASE::DIALOG_FOOTPRINT_CHECKER_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizerMain;
bSizerMain = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bUpperSizer;
bUpperSizer = new wxBoxSizer( wxVERTICAL );
bUpperSizer->SetMinSize( wxSize( 660,250 ) );
m_markersDataView = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_NO_HEADER );
bUpperSizer->Add( m_markersDataView, 1, wxALL|wxEXPAND, 5 );
bSizerMain->Add( bUpperSizer, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 10 );
wxBoxSizer* bLowerSizer;
bLowerSizer = new wxBoxSizer( wxHORIZONTAL );
m_DeleteAllMarkersButton = new wxButton( this, wxID_ANY, _("Delete All Markers"), wxDefaultPosition, wxDefaultSize, 0 );
bLowerSizer->Add( m_DeleteAllMarkersButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK );
m_sdbSizer->AddButton( m_sdbSizerOK );
m_sdbSizerCancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer->AddButton( m_sdbSizerCancel );
m_sdbSizer->Realize();
bLowerSizer->Add( m_sdbSizer, 1, wxEXPAND|wxALL, 5 );
bSizerMain->Add( bLowerSizer, 0, wxEXPAND|wxLEFT, 10 );
this->SetSizer( bSizerMain );
this->Layout();
bSizerMain->Fit( this );
this->Centre( wxBOTH );
// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnClose ) );
m_markersDataView->Connect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnSelectItem ), NULL, this );
m_markersDataView->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnLeftDClickItem ), NULL, this );
m_DeleteAllMarkersButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnDeleteAllClick ), NULL, this );
m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnCancelClick ), NULL, this );
m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnRunChecksClick ), NULL, this );
}
DIALOG_FOOTPRINT_CHECKER_BASE::~DIALOG_FOOTPRINT_CHECKER_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnClose ) );
m_markersDataView->Disconnect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnSelectItem ), NULL, this );
m_markersDataView->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnLeftDClickItem ), NULL, this );
m_DeleteAllMarkersButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnDeleteAllClick ), NULL, this );
m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnCancelClick ), NULL, this );
m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINT_CHECKER_BASE::OnRunChecksClick ), NULL, this );
}

View File

@ -0,0 +1,209 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
<property name="disconnect_mode">source_name</property>
<property name="disconnect_php_events">0</property>
<property name="disconnect_python_events">0</property>
<property name="embedded_files_path">res</property>
<property name="encoding">UTF-8</property>
<property name="event_generation">connect</property>
<property name="file">dialog_footprint_checker_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">dialog_footprint_checker</property>
<property name="namespace"></property>
<property name="path">.</property>
<property name="precompiled_header"></property>
<property name="relative_path">1</property>
<property name="skip_lua_events">1</property>
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
<property name="center">wxBOTH</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="event_handler">impl_virtual</property>
<property name="extra_style"></property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">DIALOG_FOOTPRINT_CHECKER_BASE</property>
<property name="pos"></property>
<property name="size">-1,-1</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Footprint Checker</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnClose">OnClose</event>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizerMain</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size">660,250</property>
<property name="name">bUpperSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxDataViewCtrl" expanded="1">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_markersDataView</property>
<property name="permission">protected</property>
<property name="pos"></property>
<property name="size"></property>
<property name="style">wxDV_NO_HEADER</property>
<property name="subclass">; ; forward_declare</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnDataViewCtrlSelectionChanged">OnSelectItem</event>
<event name="OnLeftDClick">OnLeftDClickItem</event>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bLowerSizer</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Delete All Markers</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_DeleteAllMarkersButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnDeleteAllClick</event>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxALL</property>
<property name="proportion">1</property>
<object class="wxStdDialogButtonSizer" expanded="0">
<property name="Apply">0</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
<property name="No">0</property>
<property name="OK">1</property>
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="minimum_size"></property>
<property name="name">m_sdbSizer</property>
<property name="permission">protected</property>
<event name="OnCancelButtonClick">OnCancelClick</event>
<event name="OnOKButtonClick">OnRunChecksClick</event>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
</wxFormBuilder_Project>

View File

@ -0,0 +1,59 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include "dialog_shim.h"
#include <wx/dataview.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/sizer.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_FOOTPRINT_CHECKER_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_FOOTPRINT_CHECKER_BASE : public DIALOG_SHIM
{
private:
protected:
wxDataViewCtrl* m_markersDataView;
wxButton* m_DeleteAllMarkersButton;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel;
// Virtual event handlers, overide them in your derived class
virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
virtual void OnSelectItem( wxDataViewEvent& event ) { event.Skip(); }
virtual void OnLeftDClickItem( wxMouseEvent& event ) { event.Skip(); }
virtual void OnDeleteAllClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRunChecksClick( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_FOOTPRINT_CHECKER_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Footprint Checker"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_FOOTPRINT_CHECKER_BASE();
};

View File

@ -92,35 +92,17 @@ void DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testFootprintCourtyardDefinitions()
if( m_drcEngine->IsErrorLimitExceeded( DRCE_MALFORMED_COURTYARD) )
continue;
std::vector<wxPoint> discontinuities;
std::vector<wxPoint> intersections;
// Run courtyard test again to get error locations
footprint->BuildPolyCourtyards( &discontinuities, &intersections);
for( wxPoint pt : discontinuities )
OUTLINE_ERROR_HANDLER errorHandler =
[&]( const wxString& msg, BOARD_ITEM* , BOARD_ITEM* , const wxPoint& pt )
{
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD );
m_msg.Printf( _( "(not a closed shape)" ) );
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
drcItem->SetItems( footprint );
reportViolation( drcItem, pt );
}
};
for( wxPoint pt : intersections )
{
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_COURTYARD );
m_msg.Printf( _( "(self-intersecting)" ) );
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
drcItem->SetItems( footprint );
reportViolation( drcItem, pt );
}
// Re-run courtyard tests to generate DRC_ITEMs
footprint->BuildPolyCourtyards( &errorHandler );
}
else if( footprint->GetPolyCourtyardFront().OutlineCount() == 0
&& footprint->GetPolyCourtyardBack().OutlineCount() == 0 )

View File

@ -80,13 +80,21 @@ private:
void DRC_TEST_PROVIDER_MISC::testOutline()
{
std::vector<wxPoint> discontinuities;
std::vector<wxPoint> intersections;
OUTLINE_ERROR_HANDLER errorHandler =
[&]( const wxString& msg, BOARD_ITEM* itemA, BOARD_ITEM* itemB, const wxPoint& pt )
{
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE );
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + msg );
drcItem->SetItems( itemA, itemB );
reportViolation( drcItem, pt );
};
SHAPE_POLY_SET boardOutlines;
if(! m_board->GetBoardPolygonOutlines( boardOutlines, &discontinuities, &intersections ) )
{
m_board->GetBoardPolygonOutlines( boardOutlines, &errorHandler );
if( boardOutlines.IsEmpty() )
{
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE );
@ -98,31 +106,6 @@ void DRC_TEST_PROVIDER_MISC::testOutline()
reportViolation( drcItem, m_board->GetBoundingBox().Centre() );
}
for( wxPoint pt : discontinuities )
{
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE );
m_msg.Printf( _( "(not a closed shape)" ) );
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
drcItem->SetItems( m_board );
reportViolation( drcItem, pt );
}
for( wxPoint pt : intersections )
{
std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_INVALID_OUTLINE );
m_msg.Printf( _( "(self-intersecting)" ) );
drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + m_msg );
drcItem->SetItems( m_board );
reportViolation( drcItem, pt );
}
}
}

View File

@ -1693,8 +1693,7 @@ std::shared_ptr<SHAPE> FOOTPRINT::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
}
void FOOTPRINT::BuildPolyCourtyards( std::vector<wxPoint>* aDiscontinuities,
std::vector<wxPoint>* aIntersections )
void FOOTPRINT::BuildPolyCourtyards( OUTLINE_ERROR_HANDLER* aErrorHandler )
{
m_poly_courtyard_front.RemoveAllContours();
m_poly_courtyard_back.RemoveAllContours();
@ -1718,20 +1717,14 @@ void FOOTPRINT::BuildPolyCourtyards( std::vector<wxPoint>* aDiscontinuities,
if( !list_front.size() && !list_back.size() )
return;
#define ARC_ERROR_MAX 0.02 /* error max in mm to approximate a arc by segments */
constexpr int errorMax = Millimeter2iu( 0.02 ); /* error max for polygonization */
if( !ConvertOutlineToPolygon( list_front, m_poly_courtyard_front, Millimeter2iu( ARC_ERROR_MAX ),
aDiscontinuities, aIntersections ) )
{
if( !ConvertOutlineToPolygon( list_front, m_poly_courtyard_front, errorMax, aErrorHandler ) )
SetFlags( MALFORMED_F_COURTYARD );
}
if( !ConvertOutlineToPolygon( list_back, m_poly_courtyard_back, Millimeter2iu( ARC_ERROR_MAX ),
aDiscontinuities, aIntersections ) )
{
if( !ConvertOutlineToPolygon( list_back, m_poly_courtyard_back, errorMax, aErrorHandler ) )
SetFlags( MALFORMED_B_COURTYARD );
}
}
void FOOTPRINT::SwapData( BOARD_ITEM* aImage )

View File

@ -35,7 +35,8 @@
#include <lib_id.h>
#include <list>
#include "zones.h"
#include <zones.h>
#include <convert_drawsegment_list_to_polygon.h>
#include <fp_text.h>
#include <zone.h>
#include <functional>
@ -669,8 +670,7 @@ public:
* @remark sets the MALFORMED_F_COURTYARD and MALFORMED_B_COURTYARD status flags if the given
* courtyard layer does not contain a (single) closed shape
*/
void BuildPolyCourtyards( std::vector<wxPoint>* aDiscontinuities = nullptr,
std::vector<wxPoint>* aIntersections = nullptr );
void BuildPolyCourtyards( OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr );
virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const override;

View File

@ -206,6 +206,9 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar()
inspectMenu->Add( ACTIONS::measureTool );
inspectMenu->AppendSeparator();
inspectMenu->Add( PCB_ACTIONS::checkFootprint );
//-- Tools menu --------------------------------------------------------
//

View File

@ -82,6 +82,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->Add( PCB_ACTIONS::footprintProperties );
m_mainToolBar->Add( PCB_ACTIONS::defaultPadProperties );
m_mainToolBar->Add( PCB_ACTIONS::checkFootprint );
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->AddTool( ID_LOAD_FOOTPRINT_FROM_BOARD, wxEmptyString,

View File

@ -36,12 +36,16 @@
#include <project.h>
#include <fp_lib_table.h>
#include <dialogs/dialog_cleanup_graphics.h>
#include <dialogs/dialog_footprint_checker.h>
#include <footprint_wizard_frame.h>
#include <kiway.h>
#include <drc/drc_results_provider.h>
FOOTPRINT_EDITOR_TOOLS::FOOTPRINT_EDITOR_TOOLS() :
PCB_TOOL_BASE( "pcbnew.ModuleEditor" ),
m_frame( nullptr )
m_frame( nullptr ),
m_checkerDialog( nullptr )
{
}
@ -54,6 +58,9 @@ FOOTPRINT_EDITOR_TOOLS::~FOOTPRINT_EDITOR_TOOLS()
void FOOTPRINT_EDITOR_TOOLS::Reset( RESET_REASON aReason )
{
m_frame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
if( m_checkerDialog )
DestroyCheckerDialog();
}
@ -454,6 +461,33 @@ int FOOTPRINT_EDITOR_TOOLS::CleanupGraphics( const TOOL_EVENT& aEvent )
}
int FOOTPRINT_EDITOR_TOOLS::CheckFootprint( const TOOL_EVENT& aEvent )
{
if( !m_checkerDialog )
{
m_checkerDialog = new DIALOG_FOOTPRINT_CHECKER( m_frame );
m_checkerDialog->Show( true );
}
else // The dialog is just not visible (because the user has double clicked on an error item)
{
m_checkerDialog->SetMarkersProvider( new BOARD_DRC_ITEMS_PROVIDER( m_frame->GetBoard() ) );
m_checkerDialog->Show( true );
}
return 0;
}
void FOOTPRINT_EDITOR_TOOLS::DestroyCheckerDialog()
{
if( m_checkerDialog )
{
m_checkerDialog->Destroy();
m_checkerDialog = nullptr;
}
}
void FOOTPRINT_EDITOR_TOOLS::setTransitions()
{
Go( &FOOTPRINT_EDITOR_TOOLS::NewFootprint, PCB_ACTIONS::newFootprint.MakeEvent() );
@ -476,6 +510,8 @@ void FOOTPRINT_EDITOR_TOOLS::setTransitions()
Go( &FOOTPRINT_EDITOR_TOOLS::CleanupGraphics, PCB_ACTIONS::cleanupGraphics.MakeEvent() );
Go( &FOOTPRINT_EDITOR_TOOLS::CheckFootprint, PCB_ACTIONS::checkFootprint.MakeEvent() );
Go( &FOOTPRINT_EDITOR_TOOLS::PinLibrary, ACTIONS::pinLibrary.MakeEvent() );
Go( &FOOTPRINT_EDITOR_TOOLS::UnpinLibrary, ACTIONS::unpinLibrary.MakeEvent() );
Go( &FOOTPRINT_EDITOR_TOOLS::ToggleFootprintTree, PCB_ACTIONS::toggleFootprintTree.MakeEvent() );

View File

@ -29,7 +29,7 @@
class FOOTPRINT_EDIT_FRAME;
class DIALOG_FOOTPRINT_CHECKER;
/**
* FOOTPRINT_EDITOR_TOOLS
@ -69,6 +69,9 @@ public:
int CleanupGraphics( const TOOL_EVENT& aEvent );
int CheckFootprint( const TOOL_EVENT& aEvent );
void DestroyCheckerDialog();
/**
* Edit the properties used for new pad creation.
*/
@ -80,6 +83,7 @@ private:
private:
FOOTPRINT_EDIT_FRAME* m_frame;
DIALOG_FOOTPRINT_CHECKER* m_checkerDialog;
// A private clipboard for cut/copy/past of an entire footprint
std::unique_ptr<FOOTPRINT> m_copiedFootprint;

View File

@ -382,6 +382,10 @@ TOOL_ACTION PCB_ACTIONS::footprintProperties( "pcbnew.ModuleEditor.footprintProp
_( "Footprint Properties..." ), "",
module_options_xpm );
TOOL_ACTION PCB_ACTIONS::checkFootprint( "pcbnew.ModuleEditor.checkFootprint",
AS_GLOBAL, 0, "",
_( "Footprint Checker" ), _( "Show the footprint checker window" ),
erc_xpm );
// GLOBAL_EDIT_TOOL
//

View File

@ -368,6 +368,8 @@ public:
static TOOL_ACTION footprintProperties;
static TOOL_ACTION defaultPadProperties;
static TOOL_ACTION checkFootprint;
/// Activation of the drawing tool (placing a PAD)
static TOOL_ACTION placePad;