Units for footprint preview widgets.

This commit is contained in:
Jeff Young 2023-01-02 22:11:44 +00:00
parent 67e6603699
commit 056349e5ea
6 changed files with 46 additions and 10 deletions

View File

@ -86,6 +86,12 @@ void FOOTPRINT_PREVIEW_WIDGET::ClearStatus()
} }
void FOOTPRINT_PREVIEW_WIDGET::SetUserUnits( EDA_UNITS aUnits )
{
m_prev_panel->SetUserUnits( aUnits );
}
void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID ) void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID )
{ {
if( !m_prev_panel || m_libid == aFPID ) if( !m_prev_panel || m_libid == aFPID )

View File

@ -305,6 +305,7 @@ wxPanel* DIALOG_CHOOSE_SYMBOL::ConstructRightPanel( wxWindow* aParent )
m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( m_parent, panel, fp_list, true ); m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( m_parent, panel, fp_list, true );
m_fp_preview = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() ); m_fp_preview = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() );
m_fp_preview->SetUserUnits( GetUserUnits() );
} }
if( m_fp_sel_ctrl ) if( m_fp_sel_ctrl )

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com> * Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
@ -25,10 +25,9 @@
#include <functional> #include <functional>
#include <import_export.h> #include <import_export.h>
#include <lib_id.h> #include <lib_id.h>
#include <eda_units.h>
#include <gal/color4d.h> #include <gal/color4d.h>
class FOOTPRINT_LOAD_EVENT;
class FOOTPRINT_PREVIEW_PANEL_BASE; class FOOTPRINT_PREVIEW_PANEL_BASE;
class KIWAY; class KIWAY;
class wxStaticText; class wxStaticText;
@ -64,6 +63,11 @@ public:
*/ */
void ClearStatus(); void ClearStatus();
/**
* Set the units for the preview.
*/
void SetUserUnits( EDA_UNITS aUnits );
/** /**
* Set the currently displayed footprint. Any footprint passed in here * Set the currently displayed footprint. Any footprint passed in here
* must have been passed to CacheFootprint before. * must have been passed to CacheFootprint before.
@ -73,12 +77,11 @@ public:
private: private:
FOOTPRINT_PREVIEW_PANEL_BASE* m_prev_panel; FOOTPRINT_PREVIEW_PANEL_BASE* m_prev_panel;
wxStaticText* m_status; wxStaticText* m_status;
wxPanel* m_statusPanel; wxPanel* m_statusPanel;
wxSizer* m_statusSizer; wxSizer* m_statusSizer;
wxSizer* m_outerSizer; wxSizer* m_outerSizer;
LIB_ID m_libid; LIB_ID m_libid;
}; };
@ -91,6 +94,8 @@ class APIEXPORT FOOTPRINT_PREVIEW_PANEL_BASE
public: public:
virtual ~FOOTPRINT_PREVIEW_PANEL_BASE() {} virtual ~FOOTPRINT_PREVIEW_PANEL_BASE() {}
virtual void SetUserUnits( EDA_UNITS aUnits ) = 0;
/** /**
* Set the currently displayed footprint. Any footprint passed in here * Set the currently displayed footprint. Any footprint passed in here
* must have been passed to CacheFootprint before. * must have been passed to CacheFootprint before.

View File

@ -174,6 +174,7 @@ wxPanel* DIALOG_CHOOSE_FOOTPRINT::ConstructRightPanel( wxWindow* aParent )
auto sizer = new wxBoxSizer( wxVERTICAL ); auto sizer = new wxBoxSizer( wxVERTICAL );
m_preview_ctrl = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() ); m_preview_ctrl = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() );
m_preview_ctrl->SetUserUnits( GetUserUnits() );
sizer->Add( m_preview_ctrl, 1, wxEXPAND | wxTOP | wxRIGHT, 5 ); sizer->Add( m_preview_ctrl, 1, wxEXPAND | wxTOP | wxRIGHT, 5 );
panel->SetSizer( sizer ); panel->SetSizer( sizer );

View File

@ -26,6 +26,7 @@
#include <base_units.h> #include <base_units.h>
#include <board.h> #include <board.h>
#include <footprint.h> #include <footprint.h>
#include <pcb_dimension.h>
#include <eda_draw_frame.h> #include <eda_draw_frame.h>
#include <footprint_preview_panel.h> #include <footprint_preview_panel.h>
#include <fp_lib_table.h> #include <fp_lib_table.h>
@ -107,6 +108,25 @@ void FOOTPRINT_PREVIEW_PANEL::renderFootprint( std::shared_ptr<FOOTPRINT> aFootp
m_currentFootprint->SetParent( m_dummyBoard.get() ); m_currentFootprint->SetParent( m_dummyBoard.get() );
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( m_userUnits );
dimension->Update();
}
return INSPECT_RESULT::CONTINUE;
};
m_currentFootprint->Visit( inspector, nullptr, { PCB_FP_DIM_LEADER_T,
PCB_FP_DIM_ORTHOGONAL_T,
PCB_FP_DIM_CENTER_T,
PCB_FP_DIM_RADIAL_T } );
// Ensure we are not using the high contrast mode to display the selected footprint // Ensure we are not using the high contrast mode to display the selected footprint
KIGFX::PAINTER* painter = GetView()->GetPainter(); KIGFX::PAINTER* painter = GetView()->GetPainter();
auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() ); auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
@ -139,7 +159,8 @@ bool FOOTPRINT_PREVIEW_PANEL::DisplayFootprint( const LIB_ID& aFPID )
try try
{ {
const FOOTPRINT* fp = fptbl->GetEnumeratedFootprint( aFPID.GetLibNickname(), aFPID.GetLibItemName() ); const FOOTPRINT* fp = fptbl->GetEnumeratedFootprint( aFPID.GetLibNickname(),
aFPID.GetLibItemName() );
if( fp ) if( fp )
m_currentFootprint.reset( static_cast<FOOTPRINT*>( fp->Duplicate() ) ); m_currentFootprint.reset( static_cast<FOOTPRINT*>( fp->Duplicate() ) );

View File

@ -53,6 +53,7 @@ public:
virtual ~FOOTPRINT_PREVIEW_PANEL( ); virtual ~FOOTPRINT_PREVIEW_PANEL( );
virtual void SetUserUnits( EDA_UNITS aUnits ) override { m_userUnits = aUnits; }
virtual bool DisplayFootprint( const LIB_ID& aFPID ) override; virtual bool DisplayFootprint( const LIB_ID& aFPID ) override;
virtual const KIGFX::COLOR4D& GetBackgroundColor() const override; virtual const KIGFX::COLOR4D& GetBackgroundColor() const override;
@ -81,6 +82,7 @@ private:
private: private:
std::unique_ptr<BOARD> m_dummyBoard; std::unique_ptr<BOARD> m_dummyBoard;
std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> m_displayOptions; std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> m_displayOptions;
EDA_UNITS m_userUnits;
std::shared_ptr<FOOTPRINT> m_currentFootprint; std::shared_ptr<FOOTPRINT> m_currentFootprint;
}; };