Fix Properties panel to reference the correct frame
The properties editors are global but the frame that they reference is not static, so we need to be able to update the frame reference when restarting pcb editor from the main window. This updates the frame, being careful to remove the signalling when closing pcbnew but keeping the instance of the editor in place. Fixes https://gitlab.com/kicad/code/kicad/issues/12297
This commit is contained in:
parent
ad6ef35c9f
commit
5fc5a2132b
|
@ -39,9 +39,27 @@ PG_UNIT_EDITOR::~PG_UNIT_EDITOR()
|
|||
}
|
||||
|
||||
|
||||
void PG_UNIT_EDITOR::UpdateFrame( EDA_DRAW_FRAME* aFrame )
|
||||
{
|
||||
m_frame = aFrame;
|
||||
|
||||
if( aFrame )
|
||||
{
|
||||
m_unitBinder = std::make_unique<PROPERTY_EDITOR_UNIT_BINDER>( m_frame );
|
||||
m_unitBinder->SetUnits( m_frame->GetUserUnits() );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_unitBinder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wxPGWindowList PG_UNIT_EDITOR::CreateControls( wxPropertyGrid* aPropGrid, wxPGProperty* aProperty,
|
||||
const wxPoint& aPos, const wxSize& aSize ) const
|
||||
{
|
||||
wxASSERT( m_unitBinder );
|
||||
|
||||
wxPGWindowList ret = wxPGTextCtrlEditor::CreateControls( aPropGrid, aProperty, aPos, aSize );
|
||||
|
||||
m_unitBinder->SetControl( ret.m_primary );
|
||||
|
@ -57,6 +75,8 @@ wxPGWindowList PG_UNIT_EDITOR::CreateControls( wxPropertyGrid* aPropGrid, wxPGPr
|
|||
bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty,
|
||||
wxWindow* aCtrl ) const
|
||||
{
|
||||
wxASSERT( m_unitBinder );
|
||||
|
||||
wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( aCtrl );
|
||||
wxCHECK_MSG( textCtrl, false, "PG_UNIT_EDITOR requires a text control!" );
|
||||
wxString textVal = textCtrl->GetValue();
|
||||
|
|
|
@ -35,13 +35,22 @@ public:
|
|||
|
||||
virtual ~PG_UNIT_EDITOR();
|
||||
|
||||
wxString GetName() const override { return wxT( "UnitEditor" ); }
|
||||
wxString GetName() const override { return wxT( "KiCadUnitEditor" ); }
|
||||
|
||||
wxPGWindowList CreateControls( wxPropertyGrid* aPropGrid, wxPGProperty* aProperty,
|
||||
const wxPoint& aPos, const wxSize& aSize ) const override;
|
||||
|
||||
bool GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty,
|
||||
wxWindow* aCtrl ) const override;
|
||||
|
||||
/**
|
||||
* When restarting an editor, the instance of PG_UNIT_EDITOR may be the same
|
||||
* but the referenced frame is different. This re-binds the frame to the editor
|
||||
* and associated controls
|
||||
* @param aFrame New frame to bind
|
||||
*/
|
||||
void UpdateFrame( EDA_DRAW_FRAME* aFrame );
|
||||
|
||||
protected:
|
||||
EDA_DRAW_FRAME* m_frame;
|
||||
|
||||
|
|
|
@ -39,23 +39,35 @@ PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* a
|
|||
: PROPERTIES_PANEL( aParent, aFrame ), m_frame( aFrame ), m_propMgr( PROPERTY_MANAGER::Instance() )
|
||||
{
|
||||
m_propMgr.Rebuild();
|
||||
bool found = false;
|
||||
|
||||
PG_UNIT_EDITOR* new_editor = new PG_UNIT_EDITOR( m_frame );
|
||||
|
||||
if( wxPGGlobalVars )
|
||||
{
|
||||
auto it = wxPGGlobalVars->m_mapEditorClasses.find( new_editor->GetName() );
|
||||
|
||||
if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
|
||||
{
|
||||
m_editor = static_cast<PG_UNIT_EDITOR*>( it->second );
|
||||
m_editor->UpdateFrame( m_frame );
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( found )
|
||||
delete new_editor;
|
||||
else
|
||||
m_editor = static_cast<PG_UNIT_EDITOR*>( wxPropertyGrid::RegisterEditorClass( new_editor ) );
|
||||
|
||||
|
||||
m_editor = wxPropertyGrid::RegisterEditorClass( new PG_UNIT_EDITOR( m_frame ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
PCB_PROPERTIES_PANEL::~PCB_PROPERTIES_PANEL()
|
||||
{
|
||||
auto it = wxPGGlobalVars->m_mapEditorClasses.find( m_editor->GetName() );
|
||||
|
||||
if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
|
||||
{
|
||||
wxPGGlobalVars->m_mapEditorClasses.erase( it );
|
||||
|
||||
delete static_cast<PG_UNIT_EDITOR*>( it->second );
|
||||
it->second = nullptr;
|
||||
}
|
||||
m_editor->UpdateFrame( nullptr );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class SELECTION;
|
|||
class BOARD;
|
||||
class PCB_EDIT_FRAME;
|
||||
class PROPERTY_MANAGER;
|
||||
class wxPGEditor;
|
||||
class PG_UNIT_EDITOR;
|
||||
|
||||
class PCB_PROPERTIES_PANEL : public PROPERTIES_PANEL
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ protected:
|
|||
|
||||
PCB_EDIT_FRAME* m_frame;
|
||||
PROPERTY_MANAGER& m_propMgr;
|
||||
wxPGEditor* m_editor;
|
||||
PG_UNIT_EDITOR* m_editor;
|
||||
|
||||
wxPGChoices m_nets;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue