From 8556bd45c2733eb95a4b0829a677414dcccbb732 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 17 Jul 2025 16:47:39 -0700 Subject: [PATCH] Handle model projection in Altium import If the model is seated on the back, KiCad just needs to rotate and offset for the board (if it is placed) Fixes https://gitlab.com/kicad/code/kicad/-/issues/213356 --- pcbnew/pcb_io/altium/altium_parser_pcb.cpp | 1 + pcbnew/pcb_io/altium/altium_pcb.cpp | 27 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pcbnew/pcb_io/altium/altium_parser_pcb.cpp b/pcbnew/pcb_io/altium/altium_parser_pcb.cpp index 35ed585c61..d8cc640e0c 100644 --- a/pcbnew/pcb_io/altium/altium_parser_pcb.cpp +++ b/pcbnew/pcb_io/altium/altium_parser_pcb.cpp @@ -702,6 +702,7 @@ ACOMPONENTBODY6::ACOMPONENTBODY6( ALTIUM_BINARY_PARSER& aReader ) rotation = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "MODEL.2D.ROTATION" ), 0. ); body_opacity_3d = ALTIUM_PROPS_UTILS::ReadDouble( properties, wxT( "BODYOPACITY3D" ), 1. ); + body_projection = ALTIUM_PROPS_UTILS::ReadInt( properties, wxT( "BODYPROJECTION" ), 0 ); aReader.SkipSubrecord(); diff --git a/pcbnew/pcb_io/altium/altium_pcb.cpp b/pcbnew/pcb_io/altium/altium_pcb.cpp index 44ae8cf67f..5705dfb74e 100644 --- a/pcbnew/pcb_io/altium/altium_pcb.cpp +++ b/pcbnew/pcb_io/altium/altium_pcb.cpp @@ -1116,6 +1116,7 @@ void ALTIUM_PCB::ParseBoard6Data( const ALTIUM_PCB_COMPOUND_FILE& aAltiumPcb } HelperCreateBoardOutline( elem.board_vertices ); + m_board->GetDesignSettings().SetBoardThickness( stackup.BuildBoardThicknessFromStackup() ); } @@ -1450,13 +1451,21 @@ void ALTIUM_PCB::ConvertComponentBody6ToFootprintItem( const ALTIUM_PCB_COMPOUND orientation = -orientation; } + VECTOR3D modelRotation( aElem.modelRotation ); + + if( aElem.body_projection == 1 ) + { + modelRotation.x += 180; + modelRotation.z += 180; + } + RotatePoint( &modelSettings.m_Offset.x, &modelSettings.m_Offset.y, orientation ); - modelSettings.m_Rotation.x = normalizeAngleDegrees( -aElem.modelRotation.x, -180, 180 ); - modelSettings.m_Rotation.y = normalizeAngleDegrees( -aElem.modelRotation.y, -180, 180 ); - modelSettings.m_Rotation.z = normalizeAngleDegrees( -aElem.modelRotation.z + aElem.rotation - + orientation.AsDegrees(), - -180, 180 ); + modelSettings.m_Rotation.x = normalizeAngleDegrees( -modelRotation.x, -180, 180 ); + modelSettings.m_Rotation.y = normalizeAngleDegrees( -modelRotation.y, -180, 180 ); + modelSettings.m_Rotation.z = normalizeAngleDegrees( -modelRotation.z + aElem.rotation + + orientation.AsDegrees(), + -180, 180 ); modelSettings.m_Opacity = aElem.body_opacity_3d; aFootprint->Models().push_back( modelSettings ); @@ -1541,6 +1550,14 @@ void ALTIUM_PCB::ParseComponentsBodies6Data( const ALTIUM_PCB_COMPOUND_FILE& orientation = -orientation; } + if( elem.body_projection == 1 ) + { + elem.modelRotation.x += 180; + elem.modelRotation.z += 180; + modelSettings.m_Offset.z = pcbIUScale.IUTomm( m_board->GetDesignSettings().GetBoardThickness() ) + + modelSettings.m_Offset.z; + } + RotatePoint( &modelSettings.m_Offset.x, &modelSettings.m_Offset.y, orientation ); modelSettings.m_Rotation.x = normalizeAngleDegrees( -elem.modelRotation.x, -180, 180 );