diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index d710adf0cb..aadc5647e0 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -142,6 +142,9 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM this ); } + aFrame->Connect( UNITS_CHANGED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL::onUnitsChanged ), + nullptr, this ); + #ifdef __WXOSX__ // Call layout once to get the proper button sizes after the bitmaps have been set Layout(); @@ -540,6 +543,27 @@ void PANEL_PREVIEW_3D_MODEL::onMouseWheelOffset( wxMouseEvent& event ) } +void PANEL_PREVIEW_3D_MODEL::onUnitsChanged( wxCommandEvent& aEvent ) +{ + double xoff_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, + xoff->GetValue() ) + / pcbIUScale.IU_PER_MM; + double yoff_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, + yoff->GetValue() ) + / pcbIUScale.IU_PER_MM; + double zoff_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, + zoff->GetValue() ) + / pcbIUScale.IU_PER_MM; + + PCB_BASE_FRAME* frame = static_cast( aEvent.GetClientData() ); + m_userUnits = frame->GetUserUnits(); + + xoff->SetValue( formatOffsetValue( xoff_mm ) ); + yoff->SetValue( formatOffsetValue( yoff_mm ) ); + zoff->SetValue( formatOffsetValue( zoff_mm ) ); +} + + void PANEL_PREVIEW_3D_MODEL::UpdateDummyFootprint( bool aReloadRequired ) { m_dummyFootprint->Models().clear(); diff --git a/3d-viewer/dialogs/panel_preview_3d_model.h b/3d-viewer/dialogs/panel_preview_3d_model.h index d0898776a8..c6400fddba 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.h +++ b/3d-viewer/dialogs/panel_preview_3d_model.h @@ -141,6 +141,8 @@ private: void doIncrementRotation( wxSpinEvent& aEvent, double aSign ); void doIncrementOffset( wxSpinEvent& aEvent, double aSign ); + void onUnitsChanged( wxCommandEvent& aEvent ); + wxString formatScaleValue( double aValue ); wxString formatRotationValue( double aValue ); wxString formatOffsetValue( double aValue );