diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index 328f7a7d02..815dd8c474 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -56,6 +56,7 @@ DIALOG_SIM_MODEL::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol, m_wasCodePreviewUpdated( true ), m_firstCategory( nullptr ), m_prevParamGridSelection( nullptr ), + m_lastParamGridWidth( 0 ), m_inKillFocus( false ) { m_modelNameCombobox->SetValidator( m_modelNameValidator ); @@ -83,33 +84,22 @@ DIALOG_SIM_MODEL::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol, | wxPG_VFB_BEEP | wxPG_VFB_MARK_CELL ); - m_paramGrid->SetColumnProportion( PARAM_COLUMN::DESCRIPTION, 50 ); - m_paramGrid->SetColumnProportion( PARAM_COLUMN::VALUE, 18 ); - m_paramGrid->SetColumnProportion( PARAM_COLUMN::UNIT, 10 ); - m_paramGrid->SetColumnProportion( PARAM_COLUMN::DEFAULT, 12 ); - m_paramGrid->SetColumnProportion( PARAM_COLUMN::TYPE, 10 ); + wxPropertyGrid* grid = m_paramGrid->GetGrid(); - if( wxPropertyGrid* grid = m_paramGrid->GetGrid() ) - { - //grid->SetCellBackgroundColour( grid->GetPropertyDefaultCell().GetBgCol() ); - //grid->SetCellTextColour( grid->GetPropertyDefaultCell().GetFgCol(); + //grid->SetCellBackgroundColour( grid->GetPropertyDefaultCell().GetBgCol() ); + //grid->SetCellTextColour( grid->GetPropertyDefaultCell().GetFgCol(); - // In wx 3.0 the color will be wrong sometimes. - grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) ); + // In wx 3.0 the color will be wrong sometimes. + grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) ); - grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this ); + grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this ); - grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN ); - grid->DedicateKey( WXK_RETURN ); - grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN ); + grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN ); + grid->DedicateKey( WXK_RETURN ); + grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN ); - grid->DedicateKey( WXK_UP ); - grid->DedicateKey( WXK_DOWN ); - } - else - { - wxFAIL; - } + grid->DedicateKey( WXK_UP ); + grid->DedicateKey( WXK_DOWN ); m_pinAssignmentsGrid->PushEventHandler( new GRID_TRICKS( m_pinAssignmentsGrid ) ); @@ -469,6 +459,8 @@ void DIALOG_SIM_MODEL::updateModelParamsTab() m_paramGrid->Expand( "Waveform" ); } + adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(), true ); + // Set all properties to default colors. // Update properties in models that have autofill. for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it ) @@ -1344,5 +1336,59 @@ void DIALOG_SIM_MODEL::onParamGridSelectionChange( wxPropertyGridEvent& aEven m_prevParamGridSelection = grid->GetSelection(); } + +template +void DIALOG_SIM_MODEL::adjustParamGridColumns( int aWidth, bool aForce ) +{ + wxPropertyGrid* grid = m_paramGridMgr->GetGrid(); + int margin = 15; + int indent = 20; + + if( aWidth != m_lastParamGridWidth || aForce ) + { + m_lastParamGridWidth = aWidth; + + grid->FitColumns(); + + std::vector colWidths; + + for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ ) + { + if( ii == 0 ) + colWidths.push_back( grid->GetState()->GetColumnWidth( ii ) + margin + indent ); + else if( ii == 1 ) + colWidths.push_back( grid->GetState()->GetColumnWidth( ii ) + margin ); + else + colWidths.push_back( 50 ); + + aWidth -= colWidths[ ii ]; + } + + // Account for scroll bars + aWidth -= ( grid->GetSize().x - grid->GetClientSize().x ); + + if( aWidth > 0 ) + colWidths[ PARAM_COLUMN::VALUE ] += aWidth; + + for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ ) + grid->SetColumnProportion( ii, colWidths[ ii ] ); + + grid->ResetColumnSizes(); + grid->RefreshEditor(); + } +} + + +template +void DIALOG_SIM_MODEL::onSizeParamGrid( wxSizeEvent& event ) +{ + adjustParamGridColumns( event.GetSize().GetX(), false ); + + event.Skip(); +} + + + + template class DIALOG_SIM_MODEL; template class DIALOG_SIM_MODEL; diff --git a/eeschema/dialogs/dialog_sim_model.h b/eeschema/dialogs/dialog_sim_model.h index b272d4a160..7c635d715a 100644 --- a/eeschema/dialogs/dialog_sim_model.h +++ b/eeschema/dialogs/dialog_sim_model.h @@ -135,10 +135,13 @@ private: void onSaveInValueCheckbox( wxCommandEvent& aEvent ) override; void onExcludeCheckbox( wxCommandEvent& aEvent ) override; void onDifferentialCheckbox( wxCommandEvent& event ) override; + void onSizeParamGrid( wxSizeEvent& event ) override; void onParamGridSetFocus( wxFocusEvent& aEvent ); void onParamGridSelectionChange( wxPropertyGridEvent& aEvent ); + void adjustParamGridColumns( int aWidth, bool aForce ); + bool isIbisLoaded() { return dynamic_cast( library() ); } private: @@ -160,6 +163,7 @@ private: wxPGProperty* m_firstCategory; // Used to add principal parameters to root. wxPGProperty* m_prevParamGridSelection; + int m_lastParamGridWidth; bool m_inKillFocus; }; diff --git a/eeschema/dialogs/dialog_sim_model_base.cpp b/eeschema/dialogs/dialog_sim_model_base.cpp index 7ec432db01..ebcaa43d38 100644 --- a/eeschema/dialogs/dialog_sim_model_base.cpp +++ b/eeschema/dialogs/dialog_sim_model_base.cpp @@ -134,6 +134,8 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c m_paramGridMgr = new wxPropertyGridManager(m_parametersPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPGMAN_DEFAULT_STYLE|wxPG_SPLITTER_AUTO_CENTER); m_paramGridMgr->SetExtraStyle( wxPG_EX_MODE_BUTTONS|wxPG_EX_NATIVE_DOUBLE_BUFFERING ); + m_paramGridMgr->SetMinSize( wxSize( 440,-1 ) ); + m_paramGrid = m_paramGridMgr->AddPage( _("Page"), wxNullBitmap ); bSizer12->Add( m_paramGridMgr, 1, wxALL|wxEXPAND, 5 ); @@ -310,6 +312,7 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c m_staticTextSpiceType->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onTypeLabelUpdate ), NULL, this ); m_typeChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onTypeChoice ), NULL, this ); m_paramGridMgr->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( DIALOG_SIM_MODEL_BASE::onParamGridChanged ), NULL, this ); + m_paramGridMgr->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SIM_MODEL_BASE::onSizeParamGrid ), NULL, this ); m_codePreview->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onCodePreviewSetFocus ), NULL, this ); m_saveInValueCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this ); m_pinAssignmentsGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridCellChange ), NULL, this ); @@ -352,6 +355,7 @@ DIALOG_SIM_MODEL_BASE::~DIALOG_SIM_MODEL_BASE() m_staticTextSpiceType->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onTypeLabelUpdate ), NULL, this ); m_typeChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onTypeChoice ), NULL, this ); m_paramGridMgr->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( DIALOG_SIM_MODEL_BASE::onParamGridChanged ), NULL, this ); + m_paramGridMgr->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SIM_MODEL_BASE::onSizeParamGrid ), NULL, this ); m_codePreview->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onCodePreviewSetFocus ), NULL, this ); m_saveInValueCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this ); m_pinAssignmentsGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridCellChange ), NULL, this ); diff --git a/eeschema/dialogs/dialog_sim_model_base.fbp b/eeschema/dialogs/dialog_sim_model_base.fbp index 7208d290b5..3b32001685 100644 --- a/eeschema/dialogs/dialog_sim_model_base.fbp +++ b/eeschema/dialogs/dialog_sim_model_base.fbp @@ -1488,7 +1488,7 @@ 0 - + 440,-1 1 m_paramGridMgr 1 @@ -1508,6 +1508,7 @@ onParamGridChanged + onSizeParamGrid Page diff --git a/eeschema/dialogs/dialog_sim_model_base.h b/eeschema/dialogs/dialog_sim_model_base.h index 319f0e1806..c8a01ecf38 100644 --- a/eeschema/dialogs/dialog_sim_model_base.h +++ b/eeschema/dialogs/dialog_sim_model_base.h @@ -111,6 +111,7 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM virtual void onTypeLabelUpdate( wxUpdateUIEvent& event ) { event.Skip(); } virtual void onTypeChoice( wxCommandEvent& event ) { event.Skip(); } virtual void onParamGridChanged( wxPropertyGridEvent& event ) { event.Skip(); } + virtual void onSizeParamGrid( wxSizeEvent& event ) { event.Skip(); } virtual void onCodePreviewSetFocus( wxFocusEvent& event ) { event.Skip(); } virtual void onSaveInValueCheckbox( wxCommandEvent& event ) { event.Skip(); } virtual void onPinAssignmentsGridCellChange( wxGridEvent& event ) { event.Skip(); }