From 18fde2b9cb51917a760ed843cf977b8738892cd1 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Wed, 15 May 2024 14:46:49 +0300 Subject: [PATCH] Fix background transparency option in kicad-cli pcb render. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17865 --- 3d-viewer/3d_canvas/board_adapter.cpp | 4 ++++ 3d-viewer/3d_canvas/board_adapter.h | 2 ++ pcbnew/pcbnew_jobs_handler.cpp | 32 +++++++++++++-------------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index 198e6fd12a..4d76ae16b5 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -698,6 +698,10 @@ std::map BOARD_ADAPTER::GetLayerColors() const } colors[ LAYER_3D_COPPER_BOTTOM ] = colors[ LAYER_3D_COPPER_TOP ]; + + for( const auto& [layer, val] : m_ColorOverrides ) + colors[layer] = val; + return colors; } diff --git a/3d-viewer/3d_canvas/board_adapter.h b/3d-viewer/3d_canvas/board_adapter.h index c8023fe905..d8c9f4ea5c 100644 --- a/3d-viewer/3d_canvas/board_adapter.h +++ b/3d-viewer/3d_canvas/board_adapter.h @@ -430,6 +430,8 @@ public: SFVEC4F m_ECO1Color; SFVEC4F m_ECO2Color; + std::map m_ColorOverrides; ///< allows to override color scheme colors + private: BOARD* m_board; S3D_CACHE* m_3dModelManager; diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 9aa4493f34..9c858c47ad 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -252,24 +252,16 @@ int PCBNEW_JOBS_HANDLER::JobExportRender( JOB* aJob ) BOARD* brd = LoadBoard( aRenderJob->m_filename, true ); brd->GetProject()->ApplyTextVars( aJob->GetVarOverrides() ); - BOARD_ADAPTER m_boardAdapter; + BOARD_ADAPTER boardAdapter; - m_boardAdapter.SetBoard( brd ); - m_boardAdapter.m_IsBoardView = false; - m_boardAdapter.m_IsPreviewer = + boardAdapter.SetBoard( brd ); + boardAdapter.m_IsBoardView = false; + boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options EDA_3D_VIEWER_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - if( aRenderJob->m_bgStyle == JOB_PCB_RENDER::BG_STYLE::TRANSPARENT - || ( aRenderJob->m_bgStyle == JOB_PCB_RENDER::BG_STYLE::DEFAULT - && aRenderJob->m_format == JOB_PCB_RENDER::FORMAT::PNG ) ) - { - BOARD_ADAPTER::g_DefaultBackgroundTop = COLOR4D( 1.0, 1.0, 1.0, 0.0 ); - BOARD_ADAPTER::g_DefaultBackgroundBot = COLOR4D( 1.0, 1.0, 1.0, 0.0 ); - } - if( aRenderJob->m_quality == JOB_PCB_RENDER::QUALITY::BASIC ) { // Silkscreen is pixelated without antialiasing @@ -309,9 +301,17 @@ int PCBNEW_JOBS_HANDLER::JobExportRender( JOB* aJob ) } cfg->m_CurrentPreset = aRenderJob->m_colorPreset; - m_boardAdapter.m_Cfg = cfg; + boardAdapter.m_Cfg = cfg; - m_boardAdapter.Set3dCacheManager( PROJECT_PCB::Get3DCacheManager( brd->GetProject() ) ); + if( aRenderJob->m_bgStyle == JOB_PCB_RENDER::BG_STYLE::TRANSPARENT + || ( aRenderJob->m_bgStyle == JOB_PCB_RENDER::BG_STYLE::DEFAULT + && aRenderJob->m_format == JOB_PCB_RENDER::FORMAT::PNG ) ) + { + boardAdapter.m_ColorOverrides[LAYER_3D_BACKGROUND_TOP] = COLOR4D( 1.0, 1.0, 1.0, 0.0 ); + boardAdapter.m_ColorOverrides[LAYER_3D_BACKGROUND_BOTTOM] = COLOR4D( 1.0, 1.0, 1.0, 0.0 ); + } + + boardAdapter.Set3dCacheManager( PROJECT_PCB::Get3DCacheManager( brd->GetProject() ) ); static std::map s_viewCmdMap = { { JOB_PCB_RENDER::SIDE::TOP, VIEW3D_TYPE::VIEW3D_TOP }, @@ -331,14 +331,14 @@ int PCBNEW_JOBS_HANDLER::JobExportRender( JOB* aJob ) camera.SetProjection( projection ); camera.SetCurWindowSize( windowSize ); - RENDER_3D_RAYTRACE_RAM raytrace( m_boardAdapter, camera ); + RENDER_3D_RAYTRACE_RAM raytrace( boardAdapter, camera ); raytrace.SetCurWindowSize( windowSize ); for( bool first = true; raytrace.Redraw( false, m_reporter, m_reporter ); first = false ) { if( first ) { - const float cmTo3D = m_boardAdapter.BiuTo3dUnits() * pcbIUScale.mmToIU( 10.0 ); + const float cmTo3D = boardAdapter.BiuTo3dUnits() * pcbIUScale.mmToIU( 10.0 ); // First redraw resets lookat point to the board center, so set up the camera here camera.ViewCommand_T1( s_viewCmdMap[aRenderJob->m_side] );