diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index c68ff492ee..73d853851a 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -194,12 +194,6 @@ 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/board.cpp b/pcbnew/board.cpp index 7ca05dec68..1569f86a98 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -978,6 +979,37 @@ wxString BOARD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const } +void BOARD::UpdateUserUnits( BOARD_ITEM* aItem, KIGFX::VIEW* aView ) +{ + INSPECTOR_FUNC inspector = + [&]( EDA_ITEM* descendant, void* aTestData ) + { + PCB_DIMENSION_BASE* dimension = static_cast( descendant ); + + if( dimension->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC ) + { + dimension->UpdateUnits(); + + if( aView ) + aView->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 } ); +} + + void BOARD::DeleteMARKERs() { // the vector does not know how to delete the PCB_MARKER, it holds pointers diff --git a/pcbnew/board.h b/pcbnew/board.h index 02ab86e9f4..2d64f8cbac 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -644,6 +644,12 @@ public: EDA_UNITS GetUserUnits() { return m_userUnits; } void SetUserUnits( EDA_UNITS aUnits ) { m_userUnits = aUnits; } + /** + * Update any references within aItem (or its descendants) to the user units. Primarily + * for automatic-unit dimensions. + */ + void UpdateUserUnits( BOARD_ITEM* aItem, KIGFX::VIEW* aView ); + /** * Extract the board outlines and build a closed polygon from lines, arcs and circle items * on edge cut layer. diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 4fc78938a9..ea31766099 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -231,12 +231,8 @@ void PCB_BASE_EDIT_FRAME::unitsChangeRefresh() if( BOARD* board = GetBoard() ) { - bool selectedItemsModified = false; - - UpdateUserUnits( board, &selectedItemsModified ); - - if( selectedItemsModified ) - m_toolManager->PostEvent( EVENTS::SelectedItemsModified ); + board->UpdateUserUnits( board, GetCanvas()->GetView() ); + m_toolManager->PostEvent( EVENTS::SelectedItemsModified ); } ReCreateAuxiliaryToolbar(); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index af4c11db71..225416f37e 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -285,45 +285,11 @@ 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 ); + GetBoard()->UpdateUserUnits( aFootprint, GetCanvas()->GetView() ); } } -void PCB_BASE_FRAME::UpdateUserUnits( BOARD_ITEM* aItem, bool* aSelectedItemsModified ) -{ - 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->UpdateUnits(); - - 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/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp index 047cd40f43..30cba65960 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp @@ -189,6 +189,7 @@ BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat ) brd->BuildConnectivity(); brd->BuildListOfNets(); brd->SynchronizeNetsAndNetClasses( false ); + brd->UpdateUserUnits( brd, nullptr ); } return brd; diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index ddc75e25d5..d4ba9c2f6b 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -1106,7 +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 ); + board->UpdateUserUnits( fp, m_frame->GetCanvas()->GetView() ); for( PAD* pad : fp->Pads() ) {