Update dimension units when opening PCBs in CLI.

Fixes https://gitlab.com/kicad/code/kicad/issues/14170
This commit is contained in:
Jeff Young 2023-03-13 20:25:27 +00:00
parent 72ebe5a429
commit a0adb59437
7 changed files with 43 additions and 48 deletions

View File

@ -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.
*/

View File

@ -47,6 +47,7 @@
#include <pcb_bitmap.h>
#include <pcb_text.h>
#include <pcb_textbox.h>
#include <pcb_dimension.h>
#include <pgm_base.h>
#include <pcbnew_settings.h>
#include <progress_reporter.h>
@ -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<PCB_DIMENSION_BASE*>( 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

View File

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

View File

@ -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();

View File

@ -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<PCB_DIMENSION_BASE*>( 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 );

View File

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

View File

@ -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() )
{