Cleanup and move to DRC_ENGINE's status reporter.

1) brace formatting
2) get rid of some autos
3) get rid of a dyn_cast that CLion claims is bad
4) use DRC_ENGINE's status reporter
This commit is contained in:
Jeff Young 2022-07-30 13:22:01 +01:00
parent 661caf1de9
commit 54213bb7f1
3 changed files with 59 additions and 40 deletions

View File

@ -186,8 +186,7 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std:
m_DRCSeverities[ DRCE_LIB_FOOTPRINT_ISSUES ] = RPT_SEVERITY_WARNING; m_DRCSeverities[ DRCE_LIB_FOOTPRINT_ISSUES ] = RPT_SEVERITY_WARNING;
m_DRCSeverities[ DRCE_LIB_FOOTPRINT_MISMATCH ] = RPT_SEVERITY_WARNING; m_DRCSeverities[ DRCE_LIB_FOOTPRINT_MISMATCH ] = RPT_SEVERITY_WARNING;
// TODO: Change to warning after testing m_DRCSeverities[ DRCE_CONNECTION_WIDTH ] = RPT_SEVERITY_WARNING;
m_DRCSeverities[ DRCE_CONNECTION_WIDTH ] = RPT_SEVERITY_IGNORE;
m_MaxError = ARC_HIGH_DEF; m_MaxError = ARC_HIGH_DEF;
m_ZoneKeepExternalFillets = false; m_ZoneKeepExternalFillets = false;

View File

@ -310,10 +310,11 @@ private:
Vertex* nz = p0->nextZ; Vertex* nz = p0->nextZ;
Vertex* pz = p0->prevZ; Vertex* pz = p0->prevZ;
auto same_point = []( const Vertex* a, const Vertex* b ) -> bool auto same_point =
{ []( const Vertex* a, const Vertex* b ) -> bool
return a && b && a->x == b->x && a->y == b->y; {
}; return a && b && a->x == b->x && a->y == b->y;
};
// If we hit a fracture point, we want to continue around the // If we hit a fracture point, we want to continue around the
// edge we are working on and not switch to the pair edge // edge we are working on and not switch to the pair edge
@ -322,14 +323,20 @@ private:
// a new fracture point, then we know that we are proceeding // a new fracture point, then we know that we are proceeding
// in the wrong direction from the fracture and should // in the wrong direction from the fracture and should
// fall through to the next point // fall through to the next point
if( same_point( p0, nz ) && if( same_point( p0, nz )
!( same_point( nz->next, nz->next->prevZ ) || same_point( nz->next, nz->next->nextZ ) ) ) && !( same_point( nz->next, nz->next->prevZ ) || same_point( nz->next, nz->next->nextZ ) ) )
{
p = nz->next; p = nz->next;
else if( same_point( p0, pz ) && }
!( same_point( pz->next, pz->next->prevZ ) || same_point( pz->next, pz->next->nextZ ) ) ) else if( same_point( p0, pz )
&& !( same_point( pz->next, pz->next->prevZ ) || same_point( pz->next, pz->next->nextZ ) ) )
{
p = pz->next; p = pz->next;
}
else else
{
p = p0->next; p = p0->next;
}
while( p0 != aB && checked < total_pts && directions != 15 ) while( p0 != aB && checked < total_pts && directions != 15 )
{ {
@ -357,14 +364,20 @@ private:
nz = p0->nextZ; nz = p0->nextZ;
pz = p0->prevZ; pz = p0->prevZ;
if( nz && same_point( p0, nz ) && if( nz && same_point( p0, nz )
!( same_point( nz->prev, nz->prev->nextZ ) || same_point( nz->prev, nz->prev->prevZ ) ) ) && !( same_point( nz->prev, nz->prev->nextZ ) || same_point( nz->prev, nz->prev->prevZ ) ) )
{
p = nz->prev; p = nz->prev;
else if( pz && same_point( p0, pz ) && }
!( same_point( pz->prev, pz->prev->nextZ ) || same_point( pz->prev, pz->prev->prevZ ) ) ) else if( pz && same_point( p0, pz )
&& !( same_point( pz->prev, pz->prev->nextZ ) || same_point( pz->prev, pz->prev->prevZ ) ) )
{
p = pz->prev; p = pz->prev;
}
else else
{
p = p0->prev; p = p0->prev;
}
directions = 0; directions = 0;
checked = 0; checked = 0;
@ -376,6 +389,7 @@ private:
directions |= ( 1 << ( 2 + bit2x ) ) + ( 1 << bit2y ); directions |= ( 1 << ( 2 + bit2x ) ) + ( 1 << bit2y );
p0 = p; p0 = p;
if( same_point( p, p->nextZ ) ) if( same_point( p, p->nextZ ) )
p = p->nextZ->prev; p = p->nextZ->prev;
else if( same_point( p, p->prevZ ) ) else if( same_point( p, p->prevZ ) )
@ -409,11 +423,15 @@ private:
} }
if( sum > 0.0 ) if( sum > 0.0 )
{
for( int i = points.PointCount() - 1; i >= 0; i--) for( int i = points.PointCount() - 1; i >= 0; i--)
tail = insertVertex( i, points.CPoint( i ), tail ); tail = insertVertex( i, points.CPoint( i ), tail );
}
else else
{
for( int i = 0; i < points.PointCount(); i++ ) for( int i = 0; i < points.PointCount(); i++ )
tail = insertVertex( i, points.CPoint( i ), tail ); tail = insertVertex( i, points.CPoint( i ), tail );
}
if( tail && ( *tail == *tail->next ) ) if( tail && ( *tail == *tail->next ) )
{ {
@ -556,28 +574,30 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
BOARD* board = m_drcEngine->GetBoard(); BOARD* board = m_drcEngine->GetBoard();
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings(); BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
PROGRESS_REPORTER* reporter = m_drcEngine->GetProgressReporter();
if( reporter && reporter->IsCancelled() ) if( m_drcEngine->IsCancelled() )
return false; // DRC cancelled return false; // DRC cancelled
std::map<PCB_LAYER_ID, std::map<int, std::set<BOARD_CONNECTED_ITEM*>>> net_items; std::map<PCB_LAYER_ID, std::map<int, std::set<BOARD_ITEM*>>> net_items;
std::atomic<size_t> done( 1 );
DRC_RTREE* tree = board->m_CopperItemRTreeCache.get(); DRC_RTREE* tree = board->m_CopperItemRTreeCache.get();
auto min_checker = auto min_checker =
[&](const std::set<BOARD_CONNECTED_ITEM*>& aItems, PCB_LAYER_ID aLayer ) -> size_t [&](const std::set<BOARD_ITEM*>& aItems, PCB_LAYER_ID aLayer ) -> size_t
{ {
if( m_drcEngine->IsCancelled() )
if( reporter && reporter->IsCancelled() )
return 0; return 0;
SHAPE_POLY_SET poly; SHAPE_POLY_SET poly;
for( BOARD_CONNECTED_ITEM* item : aItems ) for( BOARD_ITEM* item : aItems )
item->TransformShapeWithClearanceToPolygon( poly, aLayer, 0, ARC_HIGH_DEF, ERROR_OUTSIDE); {
item->TransformShapeWithClearanceToPolygon( poly, aLayer, 0, ARC_HIGH_DEF,
ERROR_OUTSIDE );
}
poly.Fracture(SHAPE_POLY_SET::PM_FAST); poly.Fracture( SHAPE_POLY_SET::PM_FAST );
int minimum_width = bds.m_MinConn; int minimum_width = bds.m_MinConn;
POLYGON_TEST test( minimum_width ); POLYGON_TEST test( minimum_width );
@ -614,8 +634,7 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
} }
} }
if( reporter ) done.fetch_add( aItems.size() );
reporter->AdvanceProgress();
return 1; return 1;
}; };
@ -632,7 +651,7 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
for( PCB_TRACK* track : board->Tracks() ) for( PCB_TRACK* track : board->Tracks() )
{ {
if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) ) if( PCB_VIA* via = dynamic_cast<PCB_VIA*>( track ) )
{ {
if( via->FlashLayer( static_cast<int>( layer ) ) ) if( via->FlashLayer( static_cast<int>( layer ) ) )
layer_items[via->GetNetCode()].emplace( via ); layer_items[via->GetNetCode()].emplace( via );
@ -662,20 +681,19 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
thread_pool& tp = GetKiCadThreadPool(); thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<size_t>> returns; std::vector<std::future<size_t>> returns;
size_t return_count = 0; size_t return_count = 0;
size_t total_count = 0;
for( auto& layer_items : net_items ) for( auto& layer_items : net_items )
return_count += layer_items.second.size(); return_count += layer_items.second.size();
returns.reserve( return_count ); returns.reserve( return_count );
if( reporter )
reporter->SetMaxProgress( return_count );
for( auto& layer_items : net_items ) for( auto& layer_items : net_items )
{ {
for( const auto& items : layer_items.second ) for( const auto& items : layer_items.second )
{ {
returns.emplace_back( tp.submit( min_checker, items.second, layer_items.first ) ); returns.emplace_back( tp.submit( min_checker, items.second, layer_items.first ) );
total_count += items.second.size();
} }
} }
@ -685,6 +703,8 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
do do
{ {
m_drcEngine->ReportProgress( static_cast<double>( done ) / total_count );
status = retval.wait_for( std::chrono::milliseconds( 100 ) ); status = retval.wait_for( std::chrono::milliseconds( 100 ) );
} while( status != std::future_status::ready ); } while( status != std::future_status::ready );
} }

View File

@ -222,7 +222,7 @@ bool DRAWING_TOOL::Init()
return m_mode == MODE::VIA; return m_mode == MODE::VIA;
}; };
auto& ctxMenu = m_menu.GetMenu(); CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
// cancel current tool goes in main context menu at the top if present // cancel current tool goes in main context menu at the top if present
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 ); ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
@ -530,17 +530,17 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
if( m_inDrawingTool ) if( m_inDrawingTool )
return 0; return 0;
REENTRANCY_GUARD guard( &m_inDrawingTool ); REENTRANCY_GUARD guard( &m_inDrawingTool );
PCB_BITMAP* image = aEvent.Parameter<PCB_BITMAP*>(); PCB_BITMAP* image = aEvent.Parameter<PCB_BITMAP*>();
bool immediateMode = image != nullptr; bool immediateMode = image != nullptr;
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
bool ignorePrimePosition = false; bool ignorePrimePosition = false;
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings(); COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
VECTOR2I cursorPos = getViewControls()->GetCursorPosition(); VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
auto selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>(); PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
@ -2039,7 +2039,7 @@ bool DRAWING_TOOL::drawShape( const std::string& aTool, PCB_SHAPE** aGraphic,
const VECTOR2I lineVector( cursorPos - VECTOR2I( twoPointManager.GetOrigin() ) ); const VECTOR2I lineVector( cursorPos - VECTOR2I( twoPointManager.GetOrigin() ) );
// get a restricted 45/H/V line from the last fixed point to the cursor // get a restricted 45/H/V line from the last fixed point to the cursor
auto newEnd = GetVectorSnapped45( lineVector, ( shape == SHAPE_T::RECT ) ); VECTOR2I newEnd = GetVectorSnapped45( lineVector, ( shape == SHAPE_T::RECT ) );
m_controls->ForceCursorPosition( true, VECTOR2I( twoPointManager.GetEnd() ) ); m_controls->ForceCursorPosition( true, VECTOR2I( twoPointManager.GetEnd() ) );
twoPointManager.SetEnd( twoPointManager.GetOrigin() + newEnd ); twoPointManager.SetEnd( twoPointManager.GetOrigin() + newEnd );
twoPointManager.SetAngleSnap( true ); twoPointManager.SetAngleSnap( true );