Move updateUnits functionality to where it can be shared.

Also call it when adding a footprint via the chooser.

Fixes https://gitlab.com/kicad/code/kicad/issues/13340
This commit is contained in:
Jeff Young 2023-01-02 19:49:22 +00:00
parent 2449f209b1
commit 67e6603699
4 changed files with 48 additions and 55 deletions

View File

@ -194,6 +194,12 @@ public:
return m_pcb;
}
/**
* Update any references within aItem (or its descendants) to the user units. Primarily
* for automatic-unit dimensions.
*/
void UpdateUserUnits( BOARD_ITEM* aItem, bool* aSelectedItemsModified = nullptr );
/**
* @return the primary data model.
*/

View File

@ -229,41 +229,11 @@ void PCB_BASE_EDIT_FRAME::unitsChangeRefresh()
if( BOARD* board = GetBoard() )
{
EDA_UNITS units = GetUserUnits();
KIGFX::VIEW* view = GetCanvas()->GetView();
bool selectedItemModified = false;
bool selectedItemsModified = false;
INSPECTOR_FUNC inspector =
[units, view, &selectedItemModified]( EDA_ITEM* aItem, void* aTestData )
{
PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
UpdateUserUnits( board, &selectedItemsModified );
if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
{
dimension->SetUnits( units );
dimension->Update();
if( dimension->IsSelected() )
selectedItemModified = true;
view->Update( dimension );
}
return INSPECT_RESULT::CONTINUE;
};
board->Visit( inspector, nullptr, { PCB_DIM_ALIGNED_T,
PCB_DIM_LEADER_T,
PCB_DIM_ORTHOGONAL_T,
PCB_DIM_CENTER_T,
PCB_DIM_RADIAL_T,
PCB_FP_DIM_ALIGNED_T,
PCB_FP_DIM_LEADER_T,
PCB_FP_DIM_ORTHOGONAL_T,
PCB_FP_DIM_CENTER_T,
PCB_FP_DIM_RADIAL_T } );
if( selectedItemModified )
if( selectedItemsModified )
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
}

View File

@ -246,29 +246,45 @@ void PCB_BASE_FRAME::AddFootprintToBoard( FOOTPRINT* aFootprint )
// it might be stored in another orientation if the lib is an archive built from a board)
aFootprint->SetOrientation( ANGLE_0 );
UpdateUserUnits( aFootprint );
}
}
void PCB_BASE_FRAME::UpdateUserUnits( BOARD_ITEM* aItem, bool* aSelectedItemsModified )
{
EDA_UNITS units = GetUserUnits();
KIGFX::VIEW* view = GetCanvas()->GetView();
INSPECTOR_FUNC inspector =
[units]( EDA_ITEM* aItem, void* aTestData )
[&]( EDA_ITEM* descendant, void* aTestData )
{
PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( descendant );
if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
{
dimension->SetUnits( units );
dimension->Update();
if( aSelectedItemsModified && dimension->IsSelected() )
*aSelectedItemsModified = true;
view->Update( dimension );
}
return INSPECT_RESULT::CONTINUE;
};
aFootprint->Visit( inspector, nullptr, { PCB_FP_DIM_ALIGNED_T,
aItem->Visit( inspector, nullptr, { PCB_DIM_ALIGNED_T,
PCB_DIM_LEADER_T,
PCB_DIM_ORTHOGONAL_T,
PCB_DIM_CENTER_T,
PCB_DIM_RADIAL_T,PCB_FP_DIM_ALIGNED_T,
PCB_FP_DIM_LEADER_T,
PCB_FP_DIM_ORTHOGONAL_T,
PCB_FP_DIM_CENTER_T,
PCB_FP_DIM_RADIAL_T } );
}
}
EDA_ITEM* PCB_BASE_FRAME::GetItem( const KIID& aId ) const

View File

@ -1106,6 +1106,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent )
// Set parent so that clearance can be loaded
fp->SetParent( board );
m_frame->UpdateUserUnits( fp );
for( PAD* pad : fp->Pads() )
{