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:
parent
2449f209b1
commit
67e6603699
|
@ -194,6 +194,12 @@ public:
|
||||||
return m_pcb;
|
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.
|
* @return the primary data model.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -229,41 +229,11 @@ void PCB_BASE_EDIT_FRAME::unitsChangeRefresh()
|
||||||
|
|
||||||
if( BOARD* board = GetBoard() )
|
if( BOARD* board = GetBoard() )
|
||||||
{
|
{
|
||||||
EDA_UNITS units = GetUserUnits();
|
bool selectedItemsModified = false;
|
||||||
KIGFX::VIEW* view = GetCanvas()->GetView();
|
|
||||||
bool selectedItemModified = false;
|
|
||||||
|
|
||||||
INSPECTOR_FUNC inspector =
|
UpdateUserUnits( board, &selectedItemsModified );
|
||||||
[units, view, &selectedItemModified]( EDA_ITEM* aItem, void* aTestData )
|
|
||||||
{
|
|
||||||
PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
|
|
||||||
|
|
||||||
if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
|
if( selectedItemsModified )
|
||||||
{
|
|
||||||
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 )
|
|
||||||
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
|
m_toolManager->PostEvent( EVENTS::SelectedItemsModified );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,31 +246,47 @@ void PCB_BASE_FRAME::AddFootprintToBoard( FOOTPRINT* aFootprint )
|
||||||
// it might be stored in another orientation if the lib is an archive built from a board)
|
// it might be stored in another orientation if the lib is an archive built from a board)
|
||||||
aFootprint->SetOrientation( ANGLE_0 );
|
aFootprint->SetOrientation( ANGLE_0 );
|
||||||
|
|
||||||
EDA_UNITS units = GetUserUnits();
|
UpdateUserUnits( aFootprint );
|
||||||
|
|
||||||
INSPECTOR_FUNC inspector =
|
|
||||||
[units]( EDA_ITEM* aItem, void* aTestData )
|
|
||||||
{
|
|
||||||
PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( aItem );
|
|
||||||
|
|
||||||
if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
|
|
||||||
{
|
|
||||||
dimension->SetUnits( units );
|
|
||||||
dimension->Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
return INSPECT_RESULT::CONTINUE;
|
|
||||||
};
|
|
||||||
|
|
||||||
aFootprint->Visit( inspector, nullptr, { 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 } );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PCB_BASE_FRAME::UpdateUserUnits( BOARD_ITEM* aItem, bool* aSelectedItemsModified )
|
||||||
|
{
|
||||||
|
EDA_UNITS units = GetUserUnits();
|
||||||
|
KIGFX::VIEW* view = GetCanvas()->GetView();
|
||||||
|
|
||||||
|
INSPECTOR_FUNC inspector =
|
||||||
|
[&]( EDA_ITEM* descendant, void* aTestData )
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
EDA_ITEM* PCB_BASE_FRAME::GetItem( const KIID& aId ) const
|
||||||
{
|
{
|
||||||
return GetBoard()->GetItem( aId );
|
return GetBoard()->GetItem( aId );
|
||||||
|
|
|
@ -1102,10 +1102,11 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
fp->SetLink( niluuid );
|
fp->SetLink( niluuid );
|
||||||
|
|
||||||
fp->SetFlags(IS_NEW ); // whatever
|
fp->SetFlags( IS_NEW ); // whatever
|
||||||
|
|
||||||
// Set parent so that clearance can be loaded
|
// Set parent so that clearance can be loaded
|
||||||
fp->SetParent( board );
|
fp->SetParent( board );
|
||||||
|
m_frame->UpdateUserUnits( fp );
|
||||||
|
|
||||||
for( PAD* pad : fp->Pads() )
|
for( PAD* pad : fp->Pads() )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue