From d5f83d26853fd7d2c7895f4c30616e96349c1959 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 4 Nov 2020 00:36:27 +0000 Subject: [PATCH] Ensure dimension units are updated when being placed * Fix the display of dimension units in the properties dialog. It was previously not showing automatic units in the dialog. * When placing dimension items (e.g. from paste or append), update the units to the board units when the dimension uses automatic units. Fixes https://gitlab.com/kicad/code/kicad/issues/6267 --- .../dialogs/dialog_dimension_properties.cpp | 32 ++++++++++++++--- pcbnew/edit.cpp | 3 +- pcbnew/tools/pcbnew_control.cpp | 35 +++++++++++++++---- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/pcbnew/dialogs/dialog_dimension_properties.cpp b/pcbnew/dialogs/dialog_dimension_properties.cpp index 721d9efb67..c9e37141fa 100644 --- a/pcbnew/dialogs/dialog_dimension_properties.cpp +++ b/pcbnew/dialogs/dialog_dimension_properties.cpp @@ -181,10 +181,14 @@ bool DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow() m_txtValue->Enable( m_dimension->GetOverrideTextEnabled() ); m_cbOverrideValue->SetValue( m_dimension->GetOverrideTextEnabled() ); - EDA_UNITS units; - m_dimension->GetUnits( units ); + switch( m_dimension->GetUnitsMode() ) + { + case DIM_UNITS_MODE::INCHES: m_cbUnits->SetSelection( 0 ); break; + case DIM_UNITS_MODE::MILS: m_cbUnits->SetSelection( 1 ); break; + case DIM_UNITS_MODE::MILLIMETRES: m_cbUnits->SetSelection( 2 ); break; + case DIM_UNITS_MODE::AUTOMATIC: m_cbUnits->SetSelection( 3 ); break; + } - m_cbUnits->SetSelection( units == EDA_UNITS::MILLIMETRES ? 2 : units == EDA_UNITS::MILS ? 1 : 0 ); m_cbUnitsFormat->SetSelection( static_cast( m_dimension->GetUnitsFormat() ) ); m_cbPrecision->SetSelection( static_cast( m_dimension->GetPrecision() ) ); @@ -298,8 +302,26 @@ void DIALOG_DIMENSION_PROPERTIES::updateDimensionFromDialog( DIMENSION* aTarget aTarget->SetSuffix( board->ConvertCrossReferencesToKIIDs( m_txtSuffix->GetValue() ) ); aTarget->SetLayer( static_cast( m_cbLayerActual->GetLayerSelection() ) ); - aTarget->SetUnits( m_frame->GetUserUnits() ); - aTarget->SetUnitsMode( static_cast( m_cbUnits->GetSelection() ) ); + switch( m_cbUnits->GetSelection() ) + { + case 0: + aTarget->SetUnitsMode( DIM_UNITS_MODE::INCHES ); + break; + + case 1: + aTarget->SetUnitsMode( DIM_UNITS_MODE::MILS ); + break; + + case 2: + aTarget->SetUnitsMode( DIM_UNITS_MODE::MILLIMETRES ); + break; + + case 3: + aTarget->SetUnitsMode( DIM_UNITS_MODE::AUTOMATIC ); + aTarget->SetUnits( m_frame->GetUserUnits() ); + break; + } + aTarget->SetUnitsFormat( static_cast( m_cbUnitsFormat->GetSelection() ) ); aTarget->SetPrecision( m_cbPrecision->GetSelection() ); aTarget->SetSuppressZeroes( m_cbSuppressZeroes->GetValue() ); diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index b48f4a6d60..7ec294838b 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -149,7 +149,8 @@ void PCB_EDIT_FRAME::OnEditItemRequest( BOARD_ITEM* aItem ) ShowTextPropertiesDialog( aItem ); break; - case PCB_SHAPE_T:ShowGraphicItemPropertiesDialog( aItem ); + case PCB_SHAPE_T: + ShowGraphicItemPropertiesDialog( aItem ); break; case PCB_ZONE_AREA_T: diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index f450051cb4..16b1b1d0b1 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -861,15 +862,37 @@ int PCBNEW_CONTROL::placeBoardItems( std::vector& aItems, bool aIsN { const_cast( item->m_Uuid ) = KIID(); - if( item->Type() == PCB_MODULE_T ) + if( selectionTool->GetEnteredGroup() && !item->GetParentGroup() ) + selectionTool->GetEnteredGroup()->AddItem( item ); + } + + // Update item attributes if needed + switch( item->Type() ) + { + case PCB_DIMENSION_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_DIM_LEADER_T: { - static_cast( item )->SetPath( KIID_PATH() ); + // Dimensions need to have their units updated if they are automatic + DIMENSION* dim = static_cast( item ); + + if( dim->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC ) + dim->SetUnits( frame()->GetUserUnits() ); + + break; } - if( selectionTool->GetEnteredGroup() && !item->GetParentGroup() ) - { - selectionTool->GetEnteredGroup()->AddItem( item ); - } + case PCB_MODULE_T: + // Update the module path with the new KIID path if the module is new + if( aIsNew ) + static_cast( item )->SetPath( KIID_PATH() ); + + break; + + default: + break; } // Add or just select items for the move/place command