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_MISMATCH ] = RPT_SEVERITY_WARNING;
// TODO: Change to warning after testing
m_DRCSeverities[ DRCE_CONNECTION_WIDTH ] = RPT_SEVERITY_IGNORE;
m_DRCSeverities[ DRCE_CONNECTION_WIDTH ] = RPT_SEVERITY_WARNING;
m_MaxError = ARC_HIGH_DEF;
m_ZoneKeepExternalFillets = false;

View File

@ -310,10 +310,11 @@ private:
Vertex* nz = p0->nextZ;
Vertex* pz = p0->prevZ;
auto same_point = []( const Vertex* a, const Vertex* b ) -> bool
{
return a && b && a->x == b->x && a->y == b->y;
};
auto same_point =
[]( const Vertex* a, const Vertex* b ) -> bool
{
return a && b && a->x == b->x && a->y == b->y;
};
// If we hit a fracture point, we want to continue around the
// 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
// in the wrong direction from the fracture and should
// fall through to the next point
if( same_point( p0, nz ) &&
!( same_point( nz->next, nz->next->prevZ ) || same_point( nz->next, nz->next->nextZ ) ) )
if( same_point( p0, nz )
&& !( same_point( nz->next, nz->next->prevZ ) || same_point( nz->next, nz->next->nextZ ) ) )
{
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;
}
else
{
p = p0->next;
}
while( p0 != aB && checked < total_pts && directions != 15 )
{
@ -357,14 +364,20 @@ private:
nz = p0->nextZ;
pz = p0->prevZ;
if( nz && same_point( p0, nz ) &&
!( same_point( nz->prev, nz->prev->nextZ ) || same_point( nz->prev, nz->prev->prevZ ) ) )
if( nz && same_point( p0, nz )
&& !( same_point( nz->prev, nz->prev->nextZ ) || same_point( nz->prev, nz->prev->prevZ ) ) )
{
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;
}
else
{
p = p0->prev;
}
directions = 0;
checked = 0;
@ -376,6 +389,7 @@ private:
directions |= ( 1 << ( 2 + bit2x ) ) + ( 1 << bit2y );
p0 = p;
if( same_point( p, p->nextZ ) )
p = p->nextZ->prev;
else if( same_point( p, p->prevZ ) )
@ -409,11 +423,15 @@ private:
}
if( sum > 0.0 )
{
for( int i = points.PointCount() - 1; i >= 0; i--)
tail = insertVertex( i, points.CPoint( i ), tail );
}
else
{
for( int i = 0; i < points.PointCount(); i++ )
tail = insertVertex( i, points.CPoint( i ), tail );
}
if( tail && ( *tail == *tail->next ) )
{
@ -556,28 +574,30 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
BOARD* board = m_drcEngine->GetBoard();
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
PROGRESS_REPORTER* reporter = m_drcEngine->GetProgressReporter();
if( reporter && reporter->IsCancelled() )
if( m_drcEngine->IsCancelled() )
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();
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( reporter && reporter->IsCancelled() )
if( m_drcEngine->IsCancelled() )
return 0;
SHAPE_POLY_SET poly;
for( BOARD_CONNECTED_ITEM* item : aItems )
item->TransformShapeWithClearanceToPolygon( poly, aLayer, 0, ARC_HIGH_DEF, ERROR_OUTSIDE);
for( BOARD_ITEM* item : aItems )
{
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;
POLYGON_TEST test( minimum_width );
@ -614,8 +634,7 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
}
}
if( reporter )
reporter->AdvanceProgress();
done.fetch_add( aItems.size() );
return 1;
};
@ -632,7 +651,7 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
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 ) ) )
layer_items[via->GetNetCode()].emplace( via );
@ -662,20 +681,19 @@ bool DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run()
thread_pool& tp = GetKiCadThreadPool();
std::vector<std::future<size_t>> returns;
size_t return_count = 0;
size_t total_count = 0;
for( auto& layer_items : net_items )
return_count += layer_items.second.size();
returns.reserve( return_count );
if( reporter )
reporter->SetMaxProgress( return_count );
for( auto& layer_items : net_items )
{
for( const auto& items : layer_items.second )
{
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
{
m_drcEngine->ReportProgress( static_cast<double>( done ) / total_count );
status = retval.wait_for( std::chrono::milliseconds( 100 ) );
} while( status != std::future_status::ready );
}

View File

@ -222,7 +222,7 @@ bool DRAWING_TOOL::Init()
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
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
@ -530,17 +530,17 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent )
if( m_inDrawingTool )
return 0;
REENTRANCY_GUARD guard( &m_inDrawingTool );
REENTRANCY_GUARD guard( &m_inDrawingTool );
PCB_BITMAP* image = aEvent.Parameter<PCB_BITMAP*>();
bool immediateMode = image != nullptr;
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
bool ignorePrimePosition = false;
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
PCB_BITMAP* image = aEvent.Parameter<PCB_BITMAP*>();
bool immediateMode = image != nullptr;
PCB_GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
bool ignorePrimePosition = false;
COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
auto selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
BOARD_COMMIT commit( m_frame );
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
BOARD_COMMIT commit( m_frame );
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() ) );
// 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() ) );
twoPointManager.SetEnd( twoPointManager.GetOrigin() + newEnd );
twoPointManager.SetAngleSnap( true );