Usability improvements to Pin Assignments in Sim Model dialog.
Fixes https://gitlab.com/kicad/code/kicad/issues/12720 Fixes https://gitlab.com/kicad/code/kicad/issues/12721
This commit is contained in:
parent
78db69bb48
commit
f3ba10ac67
|
@ -35,10 +35,14 @@
|
||||||
#include <locale_io.h>
|
#include <locale_io.h>
|
||||||
#include <wx/filedlg.h>
|
#include <wx/filedlg.h>
|
||||||
#include <wx/textfile.h>
|
#include <wx/textfile.h>
|
||||||
|
#include "grid_tricks.h"
|
||||||
|
|
||||||
using CATEGORY = SIM_MODEL::PARAM::CATEGORY;
|
using CATEGORY = SIM_MODEL::PARAM::CATEGORY;
|
||||||
|
|
||||||
|
|
||||||
|
#define USED_PIN_PREFIX wxT( "⇤" )
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
||||||
std::vector<T>& aFields )
|
std::vector<T>& aFields )
|
||||||
|
@ -112,11 +116,21 @@ DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
||||||
wxFAIL;
|
wxFAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_pinAssignmentsGrid->PushEventHandler( new GRID_TRICKS( m_pinAssignmentsGrid ) );
|
||||||
|
|
||||||
// Now all widgets have the size fixed, call FinishDialogSettings
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
||||||
finishDialogSettings();
|
finishDialogSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
DIALOG_SIM_MODEL<T>::~DIALOG_SIM_MODEL()
|
||||||
|
{
|
||||||
|
// Delete the GRID_TRICKS.
|
||||||
|
m_pinAssignmentsGrid->PopEventHandler( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
|
bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
|
||||||
{
|
{
|
||||||
|
@ -538,8 +552,6 @@ void DIALOG_SIM_MODEL<T>::updatePinAssignments()
|
||||||
modelPinString );
|
modelPinString );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxArrayString modelPinChoices = getModelPinChoices();
|
|
||||||
|
|
||||||
// Set up the Symbol column grid values and Model column cell editors with dropdown options.
|
// Set up the Symbol column grid values and Model column cell editors with dropdown options.
|
||||||
for( int i = 0; i < m_pinAssignmentsGrid->GetNumberRows(); ++i )
|
for( int i = 0; i < m_pinAssignmentsGrid->GetNumberRows(); ++i )
|
||||||
{
|
{
|
||||||
|
@ -552,15 +564,12 @@ void DIALOG_SIM_MODEL<T>::updatePinAssignments()
|
||||||
wxString curModelPinString = m_pinAssignmentsGrid->GetCellValue(
|
wxString curModelPinString = m_pinAssignmentsGrid->GetCellValue(
|
||||||
i, static_cast<int>( PIN_COLUMN::MODEL ) );
|
i, static_cast<int>( PIN_COLUMN::MODEL ) );
|
||||||
|
|
||||||
wxArrayString actualModelPinChoices( modelPinChoices );
|
wxArrayString modelPinChoices = getModelPinChoices( curModelPinString );
|
||||||
|
|
||||||
if( curModelPinString != _( "Not Connected" ) )
|
|
||||||
actualModelPinChoices.Insert( curModelPinString, 0 );
|
|
||||||
|
|
||||||
// Using `new` here shouldn't cause a memory leak because `SetCellEditor()` calls
|
// Using `new` here shouldn't cause a memory leak because `SetCellEditor()` calls
|
||||||
// `DecRef()` on its last editor.
|
// `DecRef()` on its last editor.
|
||||||
m_pinAssignmentsGrid->SetCellEditor( i, static_cast<int>( PIN_COLUMN::MODEL ),
|
m_pinAssignmentsGrid->SetCellEditor( i, static_cast<int>( PIN_COLUMN::MODEL ),
|
||||||
new wxGridCellChoiceEditor( actualModelPinChoices ) );
|
new wxGridCellChoiceEditor( modelPinChoices ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Show a preview of the symbol with the pin numbers shown.
|
// TODO: Show a preview of the symbol with the pin numbers shown.
|
||||||
|
@ -935,18 +944,21 @@ int DIALOG_SIM_MODEL<T>::getModelPinIndex( const wxString& aModelPinString ) con
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
wxArrayString DIALOG_SIM_MODEL<T>::getModelPinChoices() const
|
wxArrayString DIALOG_SIM_MODEL<T>::getModelPinChoices( const wxString& aCurrentValue ) const
|
||||||
{
|
{
|
||||||
wxArrayString modelPinChoices;
|
wxArrayString modelPinChoices;
|
||||||
|
|
||||||
for( int i = 0; i < curModel().GetPinCount(); ++i )
|
for( int i = 0; i < curModel().GetPinCount(); ++i )
|
||||||
{
|
{
|
||||||
const SIM_MODEL::PIN& modelPin = curModel().GetPin( i );
|
const SIM_MODEL::PIN& modelPin = curModel().GetPin( i );
|
||||||
|
const wxString& pinString = getModelPinString( i );
|
||||||
|
|
||||||
if( modelPin.symbolPinNumber != "" )
|
if( pinString == aCurrentValue )
|
||||||
continue;
|
modelPinChoices.Add( pinString );
|
||||||
|
else if( modelPin.symbolPinNumber != "" )
|
||||||
modelPinChoices.Add( getModelPinString( i ) );
|
modelPinChoices.Add( wxString( USED_PIN_PREFIX ) + wxS( " " ) + pinString );
|
||||||
|
else
|
||||||
|
modelPinChoices.Add( pinString );
|
||||||
}
|
}
|
||||||
|
|
||||||
modelPinChoices.Add( _( "Not Connected" ) );
|
modelPinChoices.Add( _( "Not Connected" ) );
|
||||||
|
@ -1193,10 +1205,18 @@ void DIALOG_SIM_MODEL<T>::onCodePreviewSetFocus( wxFocusEvent& aEvent )
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void DIALOG_SIM_MODEL<T>::onPinAssignmentsGridCellChange( wxGridEvent& aEvent )
|
void DIALOG_SIM_MODEL<T>::onPinAssignmentsGridCellChange( wxGridEvent& aEvent )
|
||||||
{
|
{
|
||||||
int symbolPinIndex = aEvent.GetRow();
|
int symbolPinIndex = aEvent.GetRow();
|
||||||
int oldModelPinIndex = getModelPinIndex( aEvent.GetString() );
|
wxString oldModelPinName = aEvent.GetString();
|
||||||
int modelPinIndex = getModelPinIndex(
|
wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
|
||||||
m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() ) );
|
|
||||||
|
if( oldModelPinName.StartsWith( USED_PIN_PREFIX ) )
|
||||||
|
oldModelPinName = oldModelPinName.AfterFirst( ' ' );
|
||||||
|
|
||||||
|
if( modelPinName.StartsWith( USED_PIN_PREFIX ) )
|
||||||
|
modelPinName = modelPinName.AfterFirst( ' ' );
|
||||||
|
|
||||||
|
int oldModelPinIndex = getModelPinIndex( oldModelPinName );
|
||||||
|
int modelPinIndex = getModelPinIndex( modelPinName );
|
||||||
|
|
||||||
if( oldModelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
|
if( oldModelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
|
||||||
curModel().SetPinSymbolPinNumber( oldModelPinIndex, "" );
|
curModel().SetPinSymbolPinNumber( oldModelPinIndex, "" );
|
||||||
|
|
|
@ -71,6 +71,8 @@ public:
|
||||||
|
|
||||||
DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol, std::vector<T>& aSchFields );
|
DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol, std::vector<T>& aSchFields );
|
||||||
|
|
||||||
|
~DIALOG_SIM_MODEL();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool TransferDataToWindow() override;
|
bool TransferDataToWindow() override;
|
||||||
bool TransferDataFromWindow() override;
|
bool TransferDataFromWindow() override;
|
||||||
|
@ -96,7 +98,7 @@ private:
|
||||||
wxString getSymbolPinString( int aSymbolPinNumber ) const;
|
wxString getSymbolPinString( int aSymbolPinNumber ) const;
|
||||||
wxString getModelPinString( int aModelPinIndex ) const;
|
wxString getModelPinString( int aModelPinIndex ) const;
|
||||||
int getModelPinIndex( const wxString& aModelPinString ) const;
|
int getModelPinIndex( const wxString& aModelPinString ) const;
|
||||||
wxArrayString getModelPinChoices() const;
|
wxArrayString getModelPinChoices( const wxString& aCurrentValue ) const;
|
||||||
|
|
||||||
void onRadioButton( wxCommandEvent& aEvent ) override;
|
void onRadioButton( wxCommandEvent& aEvent ) override;
|
||||||
void onBrowseButtonClick( wxCommandEvent& aEvent ) override;
|
void onBrowseButtonClick( wxCommandEvent& aEvent ) override;
|
||||||
|
|
Loading…
Reference in New Issue