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
This commit is contained in:
Ian McInerney 2020-11-04 00:36:27 +00:00
parent 123fe5a887
commit d5f83d2685
3 changed files with 58 additions and 12 deletions

View File

@ -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<int>( m_dimension->GetUnitsFormat() ) );
m_cbPrecision->SetSelection( static_cast<int>( 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<PCB_LAYER_ID>( m_cbLayerActual->GetLayerSelection() ) );
aTarget->SetUnits( m_frame->GetUserUnits() );
aTarget->SetUnitsMode( static_cast<DIM_UNITS_MODE>( 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<DIM_UNITS_FORMAT>( m_cbUnitsFormat->GetSelection() ) );
aTarget->SetPrecision( m_cbPrecision->GetSelection() );
aTarget->SetSuppressZeroes( m_cbSuppressZeroes->GetValue() );

View File

@ -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:

View File

@ -33,6 +33,7 @@
#include <board_commit.h>
#include <class_board.h>
#include <class_board_item.h>
#include <class_dimension.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
@ -861,15 +862,37 @@ int PCBNEW_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems, bool aIsN
{
const_cast<KIID&>( 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<MODULE*>( item )->SetPath( KIID_PATH() );
// Dimensions need to have their units updated if they are automatic
DIMENSION* dim = static_cast<DIMENSION*>( 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<MODULE*>( item )->SetPath( KIID_PATH() );
break;
default:
break;
}
// Add or just select items for the move/place command