From 7d47e4031c7b4d3c824d207875558320a77705e4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 30 Oct 2025 18:35:12 +0000 Subject: [PATCH] Formatting and other cleanup. --- 3d-viewer/3d_canvas/eda_3d_canvas.cpp | 11 +- .../3d_rendering/opengl/3d_spheres_gizmo.cpp | 144 ++++++------ .../raytracing/render_3d_raytrace_base.cpp | 78 ++++--- 3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp | 3 +- .../dialogs/dialog_import_choose_project.cpp | 13 +- common/dialogs/panel_grid_settings.cpp | 13 +- common/dialogs/panel_mouse_settings.cpp | 63 ++--- .../dialogs/panel_toolbar_customization.cpp | 15 +- common/eda_shape.cpp | 11 +- common/plotters/PDF_plotter.cpp | 57 ++--- common/preview_items/construction_geom.cpp | 15 +- common/preview_items/ruler_item.cpp | 53 ++--- common/project/net_settings.cpp | 63 ++--- common/scintilla_tricks.cpp | 9 +- eeschema/erc/erc.cpp | 3 +- .../kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp | 21 +- pcbnew/pcb_painter.cpp | 217 +++++++++--------- pcbnew/sel_layer.cpp | 19 +- pcbnew/toolbars_footprint_editor.cpp | 17 +- pcbnew/toolbars_pcb_editor.cpp | 38 +-- 20 files changed, 443 insertions(+), 420 deletions(-) diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index 342efbcd93..8d39701ca1 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -957,11 +957,12 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event ) RAY mouseRay = getRayAtCurrentMousePosition(); BOARD_ITEM* rollOverItem = m_3d_render_raytracing->IntersectBoardItem( mouseRay ); - auto printNetInfo = []( BOARD_CONNECTED_ITEM* aItem ) - { - return wxString::Format( _( "Net %s\tNet class %s" ), aItem->GetNet()->GetNetname(), - aItem->GetNet()->GetNetClass()->GetHumanReadableName() ); - }; + auto printNetInfo = + []( BOARD_CONNECTED_ITEM* aItem ) + { + return wxString::Format( _( "Net %s\tNet class %s" ), aItem->GetNet()->GetNetname(), + aItem->GetNet()->GetNetClass()->GetHumanReadableName() ); + }; if( rollOverItem ) { diff --git a/3d-viewer/3d_rendering/opengl/3d_spheres_gizmo.cpp b/3d-viewer/3d_rendering/opengl/3d_spheres_gizmo.cpp index ce451e45c7..c6a0b77ce4 100644 --- a/3d-viewer/3d_rendering/opengl/3d_spheres_gizmo.cpp +++ b/3d-viewer/3d_rendering/opengl/3d_spheres_gizmo.cpp @@ -187,26 +187,27 @@ void SPHERES_GIZMO::render3dSpheresGizmo( glm::mat4 aCameraRotationMatrix ) // Intersection test done - auto drawBillboardCircle = []( const glm::vec3& aCenter, float aRadius, const glm::vec3& aColor, - const glm::vec3& aCamRight, const glm::vec3& aCamUp, int aSegments = 64 ) - { - float thickness = aRadius * 0.4f; - glColor3f( aColor.r, aColor.g, aColor.b ); + auto drawBillboardCircle = + []( const glm::vec3& aCenter, float aRadius, const glm::vec3& aColor, + const glm::vec3& aCamRight, const glm::vec3& aCamUp, int aSegments = 64 ) + { + float thickness = aRadius * 0.4f; + glColor3f( aColor.r, aColor.g, aColor.b ); - glBegin( GL_TRIANGLE_STRIP ); - for( int i = 0; i <= aSegments; ++i ) - { - float angle = 2.0f * glm::pi() * i / aSegments; - glm::vec3 dir = cos( angle ) * aCamRight + sin( angle ) * aCamUp; + glBegin( GL_TRIANGLE_STRIP ); + for( int i = 0; i <= aSegments; ++i ) + { + float angle = 2.0f * glm::pi() * i / aSegments; + glm::vec3 dir = cos( angle ) * aCamRight + sin( angle ) * aCamUp; - glm::vec3 outer = aCenter + dir * ( aRadius + thickness * 0.5f ); - glm::vec3 inner = aCenter + dir * ( aRadius - thickness * 0.5f ); + glm::vec3 outer = aCenter + dir * ( aRadius + thickness * 0.5f ); + glm::vec3 inner = aCenter + dir * ( aRadius - thickness * 0.5f ); - glVertex3f( outer.x, outer.y, outer.z ); - glVertex3f( inner.x, inner.y, inner.z ); - } - glEnd(); - }; + glVertex3f( outer.x, outer.y, outer.z ); + glVertex3f( inner.x, inner.y, inner.z ); + } + glEnd(); + }; glm::vec3 camRight( aCameraRotationMatrix[0][0], aCameraRotationMatrix[1][0], aCameraRotationMatrix[2][0] ); glm::vec3 camUp( aCameraRotationMatrix[0][1], aCameraRotationMatrix[1][1], aCameraRotationMatrix[2][1] ); @@ -241,73 +242,76 @@ void SPHERES_GIZMO::render3dSpheresGizmo( glm::mat4 aCameraRotationMatrix ) glColor4f( 0.0f, 0.0f, 0.0f, 1.0f ); - auto drawX = []( const glm::vec3& aPos, float aSize, const glm::vec3& aColor, const glm::vec3& aCamRight, - const glm::vec3& aCamUp ) - { - glColor3f( aColor.r, aColor.g, aColor.b ); - glLineWidth( 3.0f ); + auto drawX = + []( const glm::vec3& aPos, float aSize, const glm::vec3& aColor, const glm::vec3& aCamRight, + const glm::vec3& aCamUp ) + { + glColor3f( aColor.r, aColor.g, aColor.b ); + glLineWidth( 3.0f ); - float h = aSize * 0.5f; + float h = aSize * 0.5f; - // Define two diagonal line directions in camera-facing plane - glm::vec3 dir1 = ( -aCamRight + aCamUp ) * h; // one diagonal - glm::vec3 dir2 = ( -aCamRight - aCamUp ) * h; // other diagonal + // Define two diagonal line directions in camera-facing plane + glm::vec3 dir1 = ( -aCamRight + aCamUp ) * h; // one diagonal + glm::vec3 dir2 = ( -aCamRight - aCamUp ) * h; // other diagonal - glBegin( GL_LINES ); - glVertex3f( ( aPos - dir1 ).x, ( aPos - dir1 ).y, ( aPos - dir1 ).z ); - glVertex3f( ( aPos + dir1 ).x, ( aPos + dir1 ).y, ( aPos + dir1 ).z ); + glBegin( GL_LINES ); + glVertex3f( ( aPos - dir1 ).x, ( aPos - dir1 ).y, ( aPos - dir1 ).z ); + glVertex3f( ( aPos + dir1 ).x, ( aPos + dir1 ).y, ( aPos + dir1 ).z ); - glVertex3f( ( aPos - dir2 ).x, ( aPos - dir2 ).y, ( aPos - dir2 ).z ); - glVertex3f( ( aPos + dir2 ).x, ( aPos + dir2 ).y, ( aPos + dir2 ).z ); - glEnd(); - }; + glVertex3f( ( aPos - dir2 ).x, ( aPos - dir2 ).y, ( aPos - dir2 ).z ); + glVertex3f( ( aPos + dir2 ).x, ( aPos + dir2 ).y, ( aPos + dir2 ).z ); + glEnd(); + }; - auto drawY = []( const glm::vec3& aPos, float aSize, const glm::vec3& aColor, const glm::vec3& aCamRight, - const glm::vec3& aCamUp ) - { - glColor3f( aColor.r, aColor.g, aColor.b ); - glLineWidth( 3.0f ); + auto drawY = + []( const glm::vec3& aPos, float aSize, const glm::vec3& aColor, const glm::vec3& aCamRight, + const glm::vec3& aCamUp ) + { + glColor3f( aColor.r, aColor.g, aColor.b ); + glLineWidth( 3.0f ); - float h = aSize * 0.5f; + float h = aSize * 0.5f; - // Top-left and top-right in screen plane - glm::vec3 topLeft = aPos + aCamUp * h - aCamRight * h; - glm::vec3 topRight = aPos + aCamUp * h + aCamRight * h; - glm::vec3 bottom = aPos - aCamUp * h; + // Top-left and top-right in screen plane + glm::vec3 topLeft = aPos + aCamUp * h - aCamRight * h; + glm::vec3 topRight = aPos + aCamUp * h + aCamRight * h; + glm::vec3 bottom = aPos - aCamUp * h; - glBegin( GL_LINES ); - glVertex3f( topLeft.x, topLeft.y, topLeft.z ); - glVertex3f( aPos.x, aPos.y, aPos.z ); + glBegin( GL_LINES ); + glVertex3f( topLeft.x, topLeft.y, topLeft.z ); + glVertex3f( aPos.x, aPos.y, aPos.z ); - glVertex3f( topRight.x, topRight.y, topRight.z ); - glVertex3f( aPos.x, aPos.y, aPos.z ); + glVertex3f( topRight.x, topRight.y, topRight.z ); + glVertex3f( aPos.x, aPos.y, aPos.z ); - glVertex3f( aPos.x, aPos.y, aPos.z ); - glVertex3f( bottom.x, bottom.y, bottom.z ); - glEnd(); - }; + glVertex3f( aPos.x, aPos.y, aPos.z ); + glVertex3f( bottom.x, bottom.y, bottom.z ); + glEnd(); + }; - auto drawZ = []( const glm::vec3& aPos, float aSize, const glm::vec3& aColor, const glm::vec3& aCamRight, - const glm::vec3& aCamUp ) - { - glColor3f( aColor.r, aColor.g, aColor.b ); - glLineWidth( 3.0f ); + auto drawZ = + []( const glm::vec3& aPos, float aSize, const glm::vec3& aColor, const glm::vec3& aCamRight, + const glm::vec3& aCamUp ) + { + glColor3f( aColor.r, aColor.g, aColor.b ); + glLineWidth( 3.0f ); - float h = aSize * 0.5f; + float h = aSize * 0.5f; - // Define corners in screen plane relative to camera - glm::vec3 topLeft = aPos + aCamUp * h - aCamRight * h; - glm::vec3 topRight = aPos + aCamUp * h + aCamRight * h; - glm::vec3 bottomLeft = aPos - aCamUp * h - aCamRight * h; - glm::vec3 bottomRight = aPos - aCamUp * h + aCamRight * h; + // Define corners in screen plane relative to camera + glm::vec3 topLeft = aPos + aCamUp * h - aCamRight * h; + glm::vec3 topRight = aPos + aCamUp * h + aCamRight * h; + glm::vec3 bottomLeft = aPos - aCamUp * h - aCamRight * h; + glm::vec3 bottomRight = aPos - aCamUp * h + aCamRight * h; - glBegin( GL_LINE_STRIP ); - glVertex3f( topLeft.x, topLeft.y, topLeft.z ); - glVertex3f( topRight.x, topRight.y, topRight.z ); - glVertex3f( bottomLeft.x, bottomLeft.y, bottomLeft.z ); - glVertex3f( bottomRight.x, bottomRight.y, bottomRight.z ); - glEnd(); - }; + glBegin( GL_LINE_STRIP ); + glVertex3f( topLeft.x, topLeft.y, topLeft.z ); + glVertex3f( topRight.x, topRight.y, topRight.z ); + glVertex3f( bottomLeft.x, bottomLeft.y, bottomLeft.z ); + glVertex3f( bottomRight.x, bottomRight.y, bottomRight.z ); + glEnd(); + }; for( size_t i = 0; i < m_spheres.size(); ++i ) { diff --git a/3d-viewer/3d_rendering/raytracing/render_3d_raytrace_base.cpp b/3d-viewer/3d_rendering/raytracing/render_3d_raytrace_base.cpp index e62e854a2b..8bd271cc51 100644 --- a/3d-viewer/3d_rendering/raytracing/render_3d_raytrace_base.cpp +++ b/3d-viewer/3d_rendering/raytracing/render_3d_raytrace_base.cpp @@ -253,26 +253,27 @@ void RENDER_3D_RAYTRACE_BASE::renderTracing( uint8_t* ptrPBO, REPORTER* aStatusR thread_pool& tp = GetKiCadThreadPool(); const int timeLimit = m_blockPositions.size() > 40000 ? 750 : 400; - auto processBlocks = [&]() - { - for( size_t iBlock = currentBlock.fetch_add( 1 ); - iBlock < m_blockPositions.size(); - iBlock = currentBlock.fetch_add( 1 ) ) - { - if( !m_blockPositionsWasProcessed[iBlock] ) + auto processBlocks = + [&]() { - renderBlockTracing( ptrPBO, iBlock ); - m_blockPositionsWasProcessed[iBlock] = 1; - numBlocksRendered++; - } + for( size_t iBlock = currentBlock.fetch_add( 1 ); + iBlock < m_blockPositions.size(); + iBlock = currentBlock.fetch_add( 1 ) ) + { + if( !m_blockPositionsWasProcessed[iBlock] ) + { + renderBlockTracing( ptrPBO, iBlock ); + m_blockPositionsWasProcessed[iBlock] = 1; + numBlocksRendered++; + } - auto diff = std::chrono::duration_cast( - std::chrono::steady_clock::now() - startTime ); + auto diff = std::chrono::duration_cast( + std::chrono::steady_clock::now() - startTime ); - if( diff.count() > timeLimit ) - break; - } - }; + if( diff.count() > timeLimit ) + break; + } + }; BS::multi_future futures; @@ -1737,31 +1738,32 @@ void RENDER_3D_RAYTRACE_BASE::initializeBlockPositions() // Hilbert curve position calculation // modified from Matters Computational, Springer 2011 // GPLv3, Copyright Joerg Arndt - constexpr auto hilbert_get_pos = []( size_t aT, size_t& aX, size_t& aY ) - { - static const size_t htab[] = { 0b0010, 0b0100, 0b1100, 0b1001, 0b1111, 0b0101, - 0b0001, 0b1000, 0b0000, 0b1010, 0b1110, 0b0111, - 0b1101, 0b1011, 0b0011, 0b0110 }; - static const size_t size = sizeof( size_t ) * 8; - size_t xv = 0; - size_t yv = 0; - size_t c01 = 0; + constexpr auto hilbert_get_pos = + []( size_t aT, size_t& aX, size_t& aY ) + { + static const size_t htab[] = { 0b0010, 0b0100, 0b1100, 0b1001, 0b1111, 0b0101, + 0b0001, 0b1000, 0b0000, 0b1010, 0b1110, 0b0111, + 0b1101, 0b1011, 0b0011, 0b0110 }; + static const size_t size = sizeof( size_t ) * 8; + size_t xv = 0; + size_t yv = 0; + size_t c01 = 0; - for( size_t i = 0; i < ( size / 2 ); ++i ) - { - size_t abi = aT >> ( size - 2 ); - aT <<= 2; + for( size_t i = 0; i < ( size / 2 ); ++i ) + { + size_t abi = aT >> ( size - 2 ); + aT <<= 2; - size_t st = htab[( c01 << 2 ) | abi]; - c01 = st & 3; + size_t st = htab[( c01 << 2 ) | abi]; + c01 = st & 3; - yv = ( yv << 1 ) | ( ( st >> 2 ) & 1 ); - xv = ( xv << 1 ) | ( st >> 3 ); - } + yv = ( yv << 1 ) | ( ( st >> 2 ) & 1 ); + xv = ( xv << 1 ) | ( st >> 3 ); + } - aX = xv; - aY = yv; - }; + aX = xv; + aY = yv; + }; size_t total_blocks = blocks_x * blocks_y; size_t pos = 0; diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp index 3c61b87247..735022b01b 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_frame.cpp @@ -270,7 +270,8 @@ void EDA_3D_VIEWER_FRAME::setupUIConditions() { return m_boardAdapter.m_Cfg->m_Render.show_model_bbox; }; - auto showNavig = [this]( const SELECTION& aSel ) + auto showNavig = + [this]( const SELECTION& aSel ) { return m_boardAdapter.m_Cfg->m_Render.show_navigator; }; diff --git a/common/dialogs/dialog_import_choose_project.cpp b/common/dialogs/dialog_import_choose_project.cpp index 89155041e9..cb8d606afb 100644 --- a/common/dialogs/dialog_import_choose_project.cpp +++ b/common/dialogs/dialog_import_choose_project.cpp @@ -37,13 +37,14 @@ DIALOG_IMPORT_CHOOSE_PROJECT::DIALOG_IMPORT_CHOOSE_PROJECT( wxWindow* aParent, // Load the project/PCB/schematic names int row = 0; - auto convertName = []( const wxString& aName, const wxString& aId ) -> wxString - { - if( aId.empty() ) - return wxEmptyString; + auto convertName = + []( const wxString& aName, const wxString& aId ) -> wxString + { + if( aId.empty() ) + return wxEmptyString; - return aName; - }; + return aName; + }; for( const IMPORT_PROJECT_DESC& desc : m_project_desc ) { diff --git a/common/dialogs/panel_grid_settings.cpp b/common/dialogs/panel_grid_settings.cpp index d85e21284f..c1a3e03228 100644 --- a/common/dialogs/panel_grid_settings.cpp +++ b/common/dialogs/panel_grid_settings.cpp @@ -217,13 +217,14 @@ bool PANEL_GRID_SETTINGS::TransferDataToWindow() GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid; // lambda that gives us a safe index into grids regardless of config idx - auto safeGrid = [this]( int idx ) -> int - { - if( idx < 0 || idx >= (int) m_grids.size() ) - return 0; + auto safeGrid = + [this]( int idx ) -> int + { + if( idx < 0 || idx >= (int) m_grids.size() ) + return 0; - return idx; - }; + return idx; + }; Layout(); diff --git a/common/dialogs/panel_mouse_settings.cpp b/common/dialogs/panel_mouse_settings.cpp index 689ae15ab7..e005d1e715 100644 --- a/common/dialogs/panel_mouse_settings.cpp +++ b/common/dialogs/panel_mouse_settings.cpp @@ -224,42 +224,43 @@ void PANEL_MOUSE_SETTINGS::OnScrollRadioButton( wxCommandEvent& event ) else if( btn == m_rbZoomAlt || btn == m_rbPanHAlt || btn == m_rbPanVAlt ) modifier = WXK_ALT; - auto column_taken = [this]( int mod ) - { - switch( mod ) - { - case 0: return m_rbZoomNone->GetValue() || m_rbPanHNone->GetValue() || m_rbPanVNone->GetValue(); - case WXK_CONTROL: return m_rbZoomCtrl->GetValue() || m_rbPanHCtrl->GetValue() || m_rbPanVCtrl->GetValue(); - case WXK_SHIFT: return m_rbZoomShift->GetValue() || m_rbPanHShift->GetValue() || m_rbPanVShift->GetValue(); - case WXK_ALT: return m_rbZoomAlt->GetValue() || m_rbPanHAlt->GetValue() || m_rbPanVAlt->GetValue(); - default: return false; - } - }; + auto column_taken = + [this]( int mod ) + { + switch( mod ) + { + case 0: return m_rbZoomNone->GetValue() || m_rbPanHNone->GetValue() || m_rbPanVNone->GetValue(); + case WXK_CONTROL: return m_rbZoomCtrl->GetValue() || m_rbPanHCtrl->GetValue() || m_rbPanVCtrl->GetValue(); + case WXK_SHIFT: return m_rbZoomShift->GetValue() || m_rbPanHShift->GetValue() || m_rbPanVShift->GetValue(); + case WXK_ALT: return m_rbZoomAlt->GetValue() || m_rbPanHAlt->GetValue() || m_rbPanVAlt->GetValue(); + default: return false; + } + }; auto assign_first_available = [&]( wxRadioButton* noneBtn, wxRadioButton* ctrlBtn, wxRadioButton* shiftBtn, wxRadioButton* altBtn ) - { - int candidates[] = { 0, WXK_CONTROL, WXK_SHIFT, WXK_ALT }; - - for( int candidate : candidates ) - { - if( candidate == modifier ) - continue; - - if( !column_taken( candidate ) ) { - switch( candidate ) - { - case 0: noneBtn->SetValue( true ); break; - case WXK_CONTROL: ctrlBtn->SetValue( true ); break; - case WXK_SHIFT: shiftBtn->SetValue( true ); break; - case WXK_ALT: altBtn->SetValue( true ); break; - } + int candidates[] = { 0, WXK_CONTROL, WXK_SHIFT, WXK_ALT }; - break; - } - } - }; + for( int candidate : candidates ) + { + if( candidate == modifier ) + continue; + + if( !column_taken( candidate ) ) + { + switch( candidate ) + { + case 0: noneBtn->SetValue( true ); break; + case WXK_CONTROL: ctrlBtn->SetValue( true ); break; + case WXK_SHIFT: shiftBtn->SetValue( true ); break; + case WXK_ALT: altBtn->SetValue( true ); break; + } + + break; + } + } + }; if( modifier == WXK_CONTROL ) { diff --git a/common/dialogs/panel_toolbar_customization.cpp b/common/dialogs/panel_toolbar_customization.cpp index 9739cc3766..7906b1bcda 100644 --- a/common/dialogs/panel_toolbar_customization.cpp +++ b/common/dialogs/panel_toolbar_customization.cpp @@ -497,13 +497,14 @@ void PANEL_TOOLBAR_CUSTOMIZATION::populateActions() logicSize = physSize / bmpsf; - auto toBitmap = [&]( BITMAPS aBmps ) - { - wxBitmap bmp = KiBitmap( aBmps, physSize ); - bmp.SetScaleFactor( bmpsf ); - wxASSERT(bmp.IsOk()); - return bmp; - }; + auto toBitmap = + [&]( BITMAPS aBmps ) + { + wxBitmap bmp = KiBitmap( aBmps, physSize ); + bmp.SetScaleFactor( bmpsf ); + wxASSERT(bmp.IsOk()); + return bmp; + }; m_actionImageList = new wxImageList( logicSize, logicSize, true, static_cast( m_availableTools.size() ) ); diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index 003482d4e5..01ab1dabd9 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -740,11 +740,12 @@ void EDA_SHAPE::move( const VECTOR2I& aMoveVector ) void EDA_SHAPE::scale( double aScale ) { - auto scalePt = [&]( VECTOR2I& pt ) - { - pt.x = KiROUND( pt.x * aScale ); - pt.y = KiROUND( pt.y * aScale ); - }; + auto scalePt = + [&]( VECTOR2I& pt ) + { + pt.x = KiROUND( pt.x * aScale ); + pt.y = KiROUND( pt.y * aScale ); + }; switch( m_shape ) { diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index 5f9470a505..1aead7b1fd 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -588,44 +588,45 @@ void PDF_PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double VECTOR2D dev_start = userToDeviceCoordinates( start ); // Deduplicate images - auto findHandleForImage = [&]( const wxImage& aCurrImage ) -> int - { - for( const auto& [imgHandle, image] : m_imageHandles ) - { - if( image.IsSameAs( aCurrImage ) ) - return imgHandle; + auto findHandleForImage = + [&]( const wxImage& aCurrImage ) -> int + { + for( const auto& [imgHandle, image] : m_imageHandles ) + { + if( image.IsSameAs( aCurrImage ) ) + return imgHandle; - if( image.GetWidth() != aCurrImage.GetWidth() ) - continue; + if( image.GetWidth() != aCurrImage.GetWidth() ) + continue; - if( image.GetHeight() != aCurrImage.GetHeight() ) - continue; + if( image.GetHeight() != aCurrImage.GetHeight() ) + continue; - if( image.GetType() != aCurrImage.GetType() ) - continue; + if( image.GetType() != aCurrImage.GetType() ) + continue; - if( image.HasAlpha() != aCurrImage.HasAlpha() ) - continue; + if( image.HasAlpha() != aCurrImage.HasAlpha() ) + continue; - if( image.HasMask() != aCurrImage.HasMask() - || image.GetMaskRed() != aCurrImage.GetMaskRed() - || image.GetMaskGreen() != aCurrImage.GetMaskGreen() - || image.GetMaskBlue() != aCurrImage.GetMaskBlue() ) - continue; + if( image.HasMask() != aCurrImage.HasMask() + || image.GetMaskRed() != aCurrImage.GetMaskRed() + || image.GetMaskGreen() != aCurrImage.GetMaskGreen() + || image.GetMaskBlue() != aCurrImage.GetMaskBlue() ) + continue; - int pixCount = image.GetWidth() * image.GetHeight(); + int pixCount = image.GetWidth() * image.GetHeight(); - if( memcmp( image.GetData(), aCurrImage.GetData(), pixCount * 3 ) != 0 ) - continue; + if( memcmp( image.GetData(), aCurrImage.GetData(), pixCount * 3 ) != 0 ) + continue; - if( image.HasAlpha() && memcmp( image.GetAlpha(), aCurrImage.GetAlpha(), pixCount ) != 0 ) - continue; + if( image.HasAlpha() && memcmp( image.GetAlpha(), aCurrImage.GetAlpha(), pixCount ) != 0 ) + continue; - return imgHandle; - } + return imgHandle; + } - return -1; - }; + return -1; + }; int imgHandle = findHandleForImage( aImage ); diff --git a/common/preview_items/construction_geom.cpp b/common/preview_items/construction_geom.cpp index da1b2a3317..7d1f41189f 100644 --- a/common/preview_items/construction_geom.cpp +++ b/common/preview_items/construction_geom.cpp @@ -86,13 +86,14 @@ void CONSTRUCTION_GEOM::ViewDraw( int aLayer, VIEW* aView ) const const bool haveSnapLine = m_snapLine && m_snapLine->Length() >= minSnapLineLength; // Avoid fighting with the snap line - const auto drawLineIfNotAlsoSnapLine = [&]( const SEG& aLine ) - { - if( !haveSnapLine || !aLine.ApproxCollinear( *m_snapLine, 1 ) ) - { - gal.DrawLine( aLine.A, aLine.B ); - } - }; + const auto drawLineIfNotAlsoSnapLine = + [&]( const SEG& aLine ) + { + if( !haveSnapLine || !aLine.ApproxCollinear( *m_snapLine, 1 ) ) + { + gal.DrawLine( aLine.A, aLine.B ); + } + }; // Draw all the items for( const DRAWABLE_INFO& drawable : m_drawables ) diff --git a/common/preview_items/ruler_item.cpp b/common/preview_items/ruler_item.cpp index c8d4130d63..16bb588f55 100644 --- a/common/preview_items/ruler_item.cpp +++ b/common/preview_items/ruler_item.cpp @@ -363,35 +363,36 @@ void RULER_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const double offsetX = 15.0; // same as DrawTextNextToCursor() double offsetY = dims.LinePitch * scale; // vertical spacing from cursor - auto fits = [&]( int sx, int sy ) - { - double left, right, top, bottom; - double xStart = cursorScreen.x + ( sx < 0 ? offsetX : -offsetX ); + auto fits = + [&]( int sx, int sy ) + { + double left, right, top, bottom; + double xStart = cursorScreen.x + ( sx < 0 ? offsetX : -offsetX ); - if( sx < 0 ) - { - left = xStart; - right = left + width * scale; - } - else - { - right = xStart; - left = right - width * scale; - } + if( sx < 0 ) + { + left = xStart; + right = left + width * scale; + } + else + { + right = xStart; + left = right - width * scale; + } - if( sy > 0 ) // above cursor - { - bottom = cursorScreen.y - offsetY; - top = bottom - height * scale; - } - else // below cursor - { - top = cursorScreen.y + offsetY; - bottom = top + height * scale; - } + if( sy > 0 ) // above cursor + { + bottom = cursorScreen.y - offsetY; + top = bottom - height * scale; + } + else // below cursor + { + top = cursorScreen.y + offsetY; + bottom = top + height * scale; + } - return left >= 0 && right <= screenSize.x && top >= 0 && bottom <= screenSize.y; - }; + return left >= 0 && right <= screenSize.x && top >= 0 && bottom <= screenSize.y; + }; std::vector candidates = { { prefX, prefY }, { -prefX, prefY }, { prefX, -prefY }, { -prefX, -prefY } }; diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp index 32d56e3004..47b7e86c60 100644 --- a/common/project/net_settings.cpp +++ b/common/project/net_settings.cpp @@ -666,38 +666,40 @@ std::shared_ptr NET_SETTINGS::GetCachedEffectiveNetClass( const wxStri std::shared_ptr NET_SETTINGS::GetEffectiveNetClass( const wxString& aNetName ) { // Lambda to fetch an explicit netclass. Returns a nullptr if not found - auto getExplicitNetclass = [this]( const wxString& netclass ) -> std::shared_ptr - { - if( netclass == NETCLASS::Default ) - return m_defaultNetClass; + auto getExplicitNetclass = + [this]( const wxString& netclass ) -> std::shared_ptr + { + if( netclass == NETCLASS::Default ) + return m_defaultNetClass; - auto ii = m_netClasses.find( netclass ); + auto ii = m_netClasses.find( netclass ); - if( ii == m_netClasses.end() ) - return {}; - else - return ii->second; - }; + if( ii == m_netClasses.end() ) + return {}; + else + return ii->second; + }; // Lambda to fetch or create an implicit netclass (defined with a label, but not configured) // These are needed as while they do not provide any netclass parameters, they do now appear in // DRC matching strings as an assigned netclass. - auto getOrAddImplicitNetcless = [this]( const wxString& netclass ) -> std::shared_ptr - { - auto ii = m_impicitNetClasses.find( netclass ); + auto getOrAddImplicitNetcless = + [this]( const wxString& netclass ) -> std::shared_ptr + { + auto ii = m_impicitNetClasses.find( netclass ); - if( ii == m_impicitNetClasses.end() ) - { - std::shared_ptr nc = std::make_shared( netclass, false ); - nc->SetPriority( std::numeric_limits::max() - 1 ); // Priority > default netclass - m_impicitNetClasses[netclass] = nc; - return nc; - } - else - { - return ii->second; - } - }; + if( ii == m_impicitNetClasses.end() ) + { + std::shared_ptr nc = std::make_shared( netclass, false ); + nc->SetPriority( std::numeric_limits::max() - 1 ); // Priority > default netclass + m_impicitNetClasses[netclass] = nc; + return nc; + } + else + { + return ii->second; + } + }; // is forced to be part of the default netclass. if( aNetName.IsEmpty() ) @@ -1052,11 +1054,12 @@ static bool isSuperSubOverbar( wxChar c ) bool NET_SETTINGS::ParseBusVector( const wxString& aBus, wxString* aName, std::vector* aMemberList ) { - auto isDigit = []( wxChar c ) - { - static wxString digits( wxT( "0123456789" ) ); - return digits.Contains( c ); - }; + auto isDigit = + []( wxChar c ) + { + static wxString digits( wxT( "0123456789" ) ); + return digits.Contains( c ); + }; size_t busLen = aBus.length(); size_t i = 0; diff --git a/common/scintilla_tricks.cpp b/common/scintilla_tricks.cpp index d1294bb1d9..5d58d65770 100644 --- a/common/scintilla_tricks.cpp +++ b/common/scintilla_tricks.cpp @@ -557,10 +557,11 @@ int SCINTILLA_TRICKS::firstNonWhitespace( int aLine, int* aWhitespaceCharCount ) void SCINTILLA_TRICKS::onScintillaUpdateUI( wxStyledTextEvent& aEvent ) { - auto isBrace = [this]( int c ) -> bool - { - return m_braces.Find( (wxChar) c ) >= 0; - }; + auto isBrace = + [this]( int c ) -> bool + { + return m_braces.Find( (wxChar) c ) >= 0; + }; // Has the caret changed position? int caretPos = m_te->GetCurrentPos(); diff --git a/eeschema/erc/erc.cpp b/eeschema/erc/erc.cpp index 2cf490a2fd..2eadb98a99 100644 --- a/eeschema/erc/erc.cpp +++ b/eeschema/erc/erc.cpp @@ -1179,7 +1179,8 @@ int ERC_TESTER::TestGroundPins() { int errors = 0; - auto isGround = []( const wxString& txt ) + auto isGround = + []( const wxString& txt ) { wxString upper = txt.Upper(); return upper.Contains( wxT( "GND" ) ); diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp index acbb927719..6416d160d5 100644 --- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp +++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp @@ -1224,18 +1224,19 @@ BOARD* PCB_IO_KICAD_SEXPR_PARSER::parseBOARD_unchecked() // Make sure the destination layer is enabled, even if not in the file m_board->SetEnabledLayers( LSET( m_board->GetEnabledLayers() ).set( destLayer ) ); - const auto visitItem = [&]( BOARD_ITEM& curr_item ) - { - LSET layers = curr_item.GetLayerSet(); + const auto visitItem = + [&]( BOARD_ITEM& curr_item ) + { + LSET layers = curr_item.GetLayerSet(); - if( layers.test( Rescue ) ) - { - layers.set( destLayer ); - layers.reset( Rescue ); - } + if( layers.test( Rescue ) ) + { + layers.set( destLayer ); + layers.reset( Rescue ); + } - curr_item.SetLayerSet( layers ); - }; + curr_item.SetLayerSet( layers ); + }; for( PCB_TRACK* track : m_board->Tracks() ) { diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 86c53b286f..9ef33c2c84 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1692,129 +1692,127 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) } } - const auto drawOneSimpleShape = [&]( const SHAPE& aShape ) - { - switch( aShape.Type() ) - { - case SH_SEGMENT: - { - const SHAPE_SEGMENT& seg = (const SHAPE_SEGMENT&) aShape; - int effectiveWidth = seg.GetWidth() + 2 * margin.x; - - if( effectiveWidth > 0 ) - m_gal->DrawSegment( seg.GetSeg().A, seg.GetSeg().B, effectiveWidth ); - - break; - } - - case SH_CIRCLE: - { - const SHAPE_CIRCLE& circle = (const SHAPE_CIRCLE&) aShape; - int effectiveRadius = circle.GetRadius() + margin.x; - - if( effectiveRadius > 0 ) - m_gal->DrawCircle( circle.GetCenter(), effectiveRadius ); - - break; - } - - case SH_RECT: - { - const SHAPE_RECT& r = (const SHAPE_RECT&) aShape; - VECTOR2I pos = r.GetPosition(); - VECTOR2I effectiveMargin = margin; - - if( effectiveMargin.x < 0 ) + const auto drawOneSimpleShape = + [&]( const SHAPE& aShape ) { - // A negative margin just produces a smaller rect. - VECTOR2I effectiveSize = r.GetSize() + effectiveMargin; - - if( effectiveSize.x > 0 && effectiveSize.y > 0 ) - m_gal->DrawRectangle( pos - effectiveMargin, pos + effectiveSize ); - } - else if( effectiveMargin.x > 0 ) - { - // A positive margin produces a larger rect, but with rounded corners - m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() ); - - // Use segments to produce the margin with rounded corners - m_gal->DrawSegment( pos, - pos + VECTOR2I( r.GetWidth(), 0 ), - effectiveMargin.x * 2 ); - m_gal->DrawSegment( pos + VECTOR2I( r.GetWidth(), 0 ), - pos + r.GetSize(), - effectiveMargin.x * 2 ); - m_gal->DrawSegment( pos + r.GetSize(), - pos + VECTOR2I( 0, r.GetHeight() ), - effectiveMargin.x * 2 ); - m_gal->DrawSegment( pos + VECTOR2I( 0, r.GetHeight() ), - pos, - effectiveMargin.x * 2 ); - } - else - { - m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() ); - } - - break; - } - - case SH_SIMPLE: - { - const SHAPE_SIMPLE& poly = static_cast( aShape ); - - if( poly.PointCount() < 2 ) // Careful of empty pads - break; - - if( margin.x < 0 ) // The poly shape must be deflated - { - SHAPE_POLY_SET outline; - outline.NewOutline(); - - for( int ii = 0; ii < poly.PointCount(); ++ii ) - outline.Append( poly.CPoint( ii ) ); - - outline.Deflate( -margin.x, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, m_maxError ); - - m_gal->DrawPolygon( outline ); - } - else - { - m_gal->DrawPolygon( poly.Vertices() ); - } - - // Now add on a rounded margin (using segments) if the margin > 0 - if( margin.x > 0 ) - { - for( size_t ii = 0; ii < poly.GetSegmentCount(); ++ii ) + switch( aShape.Type() ) { - SEG seg = poly.GetSegment( ii ); - m_gal->DrawSegment( seg.A, seg.B, margin.x * 2 ); + case SH_SEGMENT: + { + const SHAPE_SEGMENT& seg = (const SHAPE_SEGMENT&) aShape; + int effectiveWidth = seg.GetWidth() + 2 * margin.x; + + if( effectiveWidth > 0 ) + m_gal->DrawSegment( seg.GetSeg().A, seg.GetSeg().B, effectiveWidth ); + + break; } - } - break; - } + case SH_CIRCLE: + { + const SHAPE_CIRCLE& circle = (const SHAPE_CIRCLE&) aShape; + int effectiveRadius = circle.GetRadius() + margin.x; - default: - // Better not get here; we already pre-flighted the shapes... - break; - } - }; + if( effectiveRadius > 0 ) + m_gal->DrawCircle( circle.GetCenter(), effectiveRadius ); + + break; + } + + case SH_RECT: + { + const SHAPE_RECT& r = (const SHAPE_RECT&) aShape; + VECTOR2I pos = r.GetPosition(); + VECTOR2I effectiveMargin = margin; + + if( effectiveMargin.x < 0 ) + { + // A negative margin just produces a smaller rect. + VECTOR2I effectiveSize = r.GetSize() + effectiveMargin; + + if( effectiveSize.x > 0 && effectiveSize.y > 0 ) + m_gal->DrawRectangle( pos - effectiveMargin, pos + effectiveSize ); + } + else if( effectiveMargin.x > 0 ) + { + // A positive margin produces a larger rect, but with rounded corners + m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() ); + + // Use segments to produce the margin with rounded corners + m_gal->DrawSegment( pos, + pos + VECTOR2I( r.GetWidth(), 0 ), + effectiveMargin.x * 2 ); + m_gal->DrawSegment( pos + VECTOR2I( r.GetWidth(), 0 ), + pos + r.GetSize(), + effectiveMargin.x * 2 ); + m_gal->DrawSegment( pos + r.GetSize(), + pos + VECTOR2I( 0, r.GetHeight() ), + effectiveMargin.x * 2 ); + m_gal->DrawSegment( pos + VECTOR2I( 0, r.GetHeight() ), + pos, + effectiveMargin.x * 2 ); + } + else + { + m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() ); + } + + break; + } + + case SH_SIMPLE: + { + const SHAPE_SIMPLE& poly = static_cast( aShape ); + + if( poly.PointCount() < 2 ) // Careful of empty pads + break; + + if( margin.x < 0 ) // The poly shape must be deflated + { + SHAPE_POLY_SET outline; + outline.NewOutline(); + + for( int ii = 0; ii < poly.PointCount(); ++ii ) + outline.Append( poly.CPoint( ii ) ); + + outline.Deflate( -margin.x, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, m_maxError ); + + m_gal->DrawPolygon( outline ); + } + else + { + m_gal->DrawPolygon( poly.Vertices() ); + } + + // Now add on a rounded margin (using segments) if the margin > 0 + if( margin.x > 0 ) + { + for( size_t ii = 0; ii < poly.GetSegmentCount(); ++ii ) + { + SEG seg = poly.GetSegment( ii ); + m_gal->DrawSegment( seg.A, seg.B, margin.x * 2 ); + } + } + + break; + } + + default: + // Better not get here; we already pre-flighted the shapes... + break; + } + }; if( simpleShapes ) { for( const SHAPE* shape : shapes->Shapes() ) - { drawOneSimpleShape( *shape ); - } } else { // This is expensive. Avoid if possible. SHAPE_POLY_SET polySet; - aPad->TransformShapeToPolygon( polySet, ToLAYER_ID( aLayer ), margin.x, m_maxError, - ERROR_INSIDE ); + aPad->TransformShapeToPolygon( polySet, ToLAYER_ID( aLayer ), margin.x, m_maxError, ERROR_INSIDE ); m_gal->DrawPolygon( polySet ); } } @@ -1837,8 +1835,7 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) if( aPad->FlashLayer( copperLayerForClearance ) && clearance > 0 ) { - auto shape = std::dynamic_pointer_cast( - aPad->GetEffectiveShape( pcbLayer ) ); + auto shape = std::dynamic_pointer_cast( aPad->GetEffectiveShape( pcbLayer ) ); if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_SEGMENT ) { diff --git a/pcbnew/sel_layer.cpp b/pcbnew/sel_layer.cpp index 5d8834f628..b02e453fd2 100644 --- a/pcbnew/sel_layer.cpp +++ b/pcbnew/sel_layer.cpp @@ -611,16 +611,17 @@ private: */ void setCurrentSelection( int aLeftRow, int aRightRow ) { - const auto selectGridRow = []( wxGrid& aGrid, int aRow, bool aSelect ) - { - // At start, there is no old row - if( aRow < 0 ) - return; + const auto selectGridRow = + []( wxGrid& aGrid, int aRow, bool aSelect ) + { + // At start, there is no old row + if( aRow < 0 ) + return; - const wxString val = aSelect ? wxT( "1" ) : wxEmptyString; - aGrid.SetCellValue( aRow, (int) CU_LAYER_COLNUMS::SELECT, val ); - aGrid.SetGridCursor( aRow, (int) CU_LAYER_COLNUMS::COLOR ); - }; + const wxString val = aSelect ? wxT( "1" ) : wxEmptyString; + aGrid.SetCellValue( aRow, (int) CU_LAYER_COLNUMS::SELECT, val ); + aGrid.SetGridCursor( aRow, (int) CU_LAYER_COLNUMS::COLOR ); + }; if( m_leftCurrRow != aLeftRow ) { diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 340e7ae327..1e9f6535b1 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -126,16 +126,17 @@ std::optional FOOTPRINT_EDIT_TOOLBAR_SETTINGS::DefaultToo /* TODO (ISM): Implement context menus PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - auto makeArcMenu = [&]() - { - std::unique_ptr arcMenu = std::make_unique( false, selTool ); + auto makeArcMenu = + [&]() + { + std::unique_ptr arcMenu = std::make_unique( false, selTool ); - arcMenu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); + arcMenu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); + arcMenu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); + arcMenu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); - return arcMenu; - }; + return arcMenu; + }; m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawArc, makeArcMenu() ); */ diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index ea1f36a926..e9dbd7fe8a 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -241,32 +241,34 @@ std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarCo /* TODO (ISM): Support context menus PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool(); - auto makeArcMenu = [&]() - { - std::unique_ptr arcMenu = std::make_unique( false, selTool ); + auto makeArcMenu = + [&]() + { + std::unique_ptr arcMenu = std::make_unique( false, selTool ); - arcMenu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); - arcMenu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); + arcMenu->Add( ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK ); + arcMenu->Add( ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK ); + arcMenu->Add( ACTIONS::pointEditorArcKeepRadius, ACTION_MENU::CHECK ); - return arcMenu; - }; + return arcMenu; + }; m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawArc, makeArcMenu() ); - auto makeRouteMenu = [&]() - { - std::unique_ptr routeMenu = std::make_unique( false, selTool ); + auto makeRouteMenu = + [&]() + { + std::unique_ptr routeMenu = std::make_unique( false, selTool ); - routeMenu->Add( PCB_ACTIONS::routerHighlightMode, ACTION_MENU::CHECK ); - routeMenu->Add( PCB_ACTIONS::routerShoveMode, ACTION_MENU::CHECK ); - routeMenu->Add( PCB_ACTIONS::routerWalkaroundMode, ACTION_MENU::CHECK ); + routeMenu->Add( PCB_ACTIONS::routerHighlightMode, ACTION_MENU::CHECK ); + routeMenu->Add( PCB_ACTIONS::routerShoveMode, ACTION_MENU::CHECK ); + routeMenu->Add( PCB_ACTIONS::routerWalkaroundMode, ACTION_MENU::CHECK ); - routeMenu->AppendSeparator(); - routeMenu->Add( PCB_ACTIONS::routerSettingsDialog ); + routeMenu->AppendSeparator(); + routeMenu->Add( PCB_ACTIONS::routerSettingsDialog ); - return routeMenu; - }; + return routeMenu; + }; m_tbRight->AddToolContextMenu( PCB_ACTIONS::routeSingleTrack, makeRouteMenu() ); m_tbRight->AddToolContextMenu( PCB_ACTIONS::routeDiffPair, makeRouteMenu() );