diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 29ef8848dc..0a51db4630 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -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. */ diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 7483e40672..e4e4348aef 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -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( 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 ); } diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 9e165e8674..8f4fd9a90b 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -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) aFootprint->SetOrientation( ANGLE_0 ); - EDA_UNITS units = GetUserUnits(); - - INSPECTOR_FUNC inspector = - [units]( EDA_ITEM* aItem, void* aTestData ) - { - PCB_DIMENSION_BASE* dimension = static_cast( 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 } ); + UpdateUserUnits( aFootprint ); } } +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( 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 { return GetBoard()->GetItem( aId ); diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index a1b9e3239c..81e8e7f4ca 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -1102,10 +1102,11 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent ) fp->SetLink( niluuid ); - fp->SetFlags(IS_NEW ); // whatever + fp->SetFlags( IS_NEW ); // whatever // Set parent so that clearance can be loaded fp->SetParent( board ); + m_frame->UpdateUserUnits( fp ); for( PAD* pad : fp->Pads() ) {