diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index 83b39a338a..d513b8f6b2 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -40,6 +40,7 @@ #include #include #include +#include PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAME* aFrame, FOOTPRINT* aFootprint, @@ -80,7 +81,8 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM { m_spinXscale, m_spinYscale, m_spinZscale, m_spinXrot, m_spinYrot, m_spinZrot, - m_spinXoffset,m_spinYoffset, m_spinZoffset + m_spinXoffset,m_spinYoffset, m_spinZoffset, + m_spinBoardThickness }; for( wxSpinButton* button : spinButtonList ) @@ -130,6 +132,10 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM this ); } + // load initial board thickness value + boardthickness->ChangeValue( formatBoardThicknessValue( + Iu2Millimeter( m_dummyBoard->GetDesignSettings().GetBoardThickness() ) ) ); + #ifdef __WXOSX__ // Call layout once to get the proper button sizes after the bitmaps have been set Layout(); @@ -268,6 +274,15 @@ wxString PANEL_PREVIEW_3D_MODEL::formatOffsetValue( double aValue ) EDA_UNIT_UTILS::GetText( m_userUnits ) ); } +wxString PANEL_PREVIEW_3D_MODEL::formatBoardThicknessValue( double aValue ) +{ + // Convert from internal units (mm) to user units + if( m_userUnits == EDA_UNITS::INCHES ) + aValue /= 25.4f; + + return wxString::Format( "%.2f %s", aValue, GetAbbreviatedUnitsLabel( m_userUnits ) ); +} + void PANEL_PREVIEW_3D_MODEL::SetSelectedModel( int idx ) { @@ -361,6 +376,15 @@ void PANEL_PREVIEW_3D_MODEL::onOpacitySlider( wxCommandEvent& event ) } } +void PANEL_PREVIEW_3D_MODEL::updateBoardThickness( wxCommandEvent& event ) +{ + m_boardAdapter.GetBoard()->GetDesignSettings().SetBoardThickness( + ValueFromString( m_userUnits, boardthickness->GetValue() ) ); + + m_previewPane->ReloadRequest(); + m_previewPane->Request_refresh(); +} + void PANEL_PREVIEW_3D_MODEL::doIncrementScale( wxSpinEvent& event, double aSign ) { @@ -433,6 +457,25 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign } +void PANEL_PREVIEW_3D_MODEL::doIncrementBoardThickness( wxSpinEvent& aEvent, double aSign ) +{ + wxSpinButton* spinCtrl = (wxSpinButton*) aEvent.GetEventObject(); + wxTextCtrl* textCtrl = boardthickness; + + double step = BOARD_THICKNESS_INCREMENT_MM; + + if( m_userUnits == EDA_UNITS::INCHES ) + step = BOARD_THICKNESS_INCREMENT_MIL / 1000.0; + + double curr_value = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM; + + curr_value += ( step * aSign ); + curr_value = std::max( 0.0, curr_value ); + curr_value = std::min( curr_value, MAX_BOARD_THICKNESS ); + + textCtrl->SetValue( formatBoardThicknessValue( curr_value ) ); +} + void PANEL_PREVIEW_3D_MODEL::onMouseWheelScale( wxMouseEvent& event ) { wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject(); @@ -510,6 +553,33 @@ void PANEL_PREVIEW_3D_MODEL::onMouseWheelOffset( wxMouseEvent& event ) textCtrl->SetValue( formatOffsetValue( curr_value_mm ) ); } +void PANEL_PREVIEW_3D_MODEL::onMouseWheelBoardThickness( wxMouseEvent& event ) +{ + wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject(); + + double step = BOARD_THICKNESS_INCREMENT_MM; + + if( event.ShiftDown( )) + step = BOARD_THICKNESS_INCREMENT_MM_FINE; + + if(m_userUnits==EDA_UNITS::INCHES) + { + step = BOARD_THICKNESS_INCREMENT_MIL/1000.0; + + if(event.ShiftDown()) + step = BOARD_THICKNESS_INCREMENT_MIL_FINE/1000.0; + } + + if (event.GetWheelRotation()>=0) + step = -step; + + double curr_value = DoubleValueFromString(m_userUnits, textCtrl->GetValue()) / IU_PER_MM; + + curr_value += step; + curr_value = std::max( 0.0, curr_value ); + curr_value = std::min( curr_value, MAX_BOARD_THICKNESS ); +} + void PANEL_PREVIEW_3D_MODEL::UpdateDummyFootprint( bool aReloadRequired ) { diff --git a/3d-viewer/dialogs/panel_preview_3d_model.h b/3d-viewer/dialogs/panel_preview_3d_model.h index a635fb3b6f..5eafeabf27 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.h +++ b/3d-viewer/dialogs/panel_preview_3d_model.h @@ -48,6 +48,7 @@ #define MAX_SCALE 10000.0 #define MAX_ROTATION 180.0 #define MAX_OFFSET 1000.0 +#define MAX_BOARD_THICKNESS 100.0 #define SCALE_INCREMENT_FINE 0.02 #define SCALE_INCREMENT 0.1 @@ -62,6 +63,12 @@ #define OFFSET_INCREMENT_MIL 25.0 #define OFFSET_INCREMENT_MIL_FINE 5.0 +#define BOARD_THICKNESS_INCREMENT_MM 0.2 +#define BOARD_THICKNESS_INCREMENT_MM_FINE 0.05 + +#define BOARD_THICKNESS_INCREMENT_MIL 10.0 +#define BOARD_THICKNESS_INCREMENT_MIL_FINE 2.0 + // Declared classes to create pointers class WX_INFOBAR; @@ -116,6 +123,7 @@ private: void onMouseWheelScale( wxMouseEvent& event ) override; void onMouseWheelRot( wxMouseEvent& event ) override; void onMouseWheelOffset( wxMouseEvent& event ) override; + void onMouseWheelBoardThickness( wxMouseEvent& event ) override; void onIncrementRot( wxSpinEvent& event ) override { @@ -141,16 +149,28 @@ private: { doIncrementOffset( event, -1.0 ); } + void onIncrementBoardThickness( wxSpinEvent& event ) override + { + doIncrementBoardThickness( event, 1.0 ); + } + void onDecrementBoardThickness( wxSpinEvent& event ) override + { + doIncrementBoardThickness( event, -1.0 ); + } void onOpacitySlider( wxCommandEvent& event ) override; + void updateBoardThickness( wxCommandEvent& event ) override; + void doIncrementScale( wxSpinEvent& aEvent, double aSign ); void doIncrementRotation( wxSpinEvent& aEvent, double aSign ); void doIncrementOffset( wxSpinEvent& aEvent, double aSign ); + void doIncrementBoardThickness( wxSpinEvent& aEvent, double aSign ); wxString formatScaleValue( double aValue ); wxString formatRotationValue( double aValue ); wxString formatOffsetValue( double aValue ); + wxString formatBoardThicknessValue( double aValue ); void View3DISO( wxCommandEvent& event ) override { diff --git a/3d-viewer/dialogs/panel_preview_3d_model_base.cpp b/3d-viewer/dialogs/panel_preview_3d_model_base.cpp index 99eb486c95..3e586b2ab4 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model_base.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Sep 12 2021) +// C++ code generated with wxFormBuilder (version 3.10.0-0-g4761b0c5) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -159,7 +159,28 @@ PANEL_PREVIEW_3D_MODEL_BASE::PANEL_PREVIEW_3D_MODEL_BASE( wxWindow* parent, wxWi sbSizer4->Add( m_opacity, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); - bSizerLeft->Add( sbSizer4, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); + bSizerLeft->Add( sbSizer4, 1, wxEXPAND|wxLEFT|wxRIGHT, 5 ); + + wxStaticBoxSizer* sbSizerBoardThickness; + sbSizerBoardThickness = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Board Thickness") ), wxVERTICAL ); + + wxFlexGridSizer* fgSizerBoardThickness; + fgSizerBoardThickness = new wxFlexGridSizer( 0, 2, 0, 0 ); + fgSizerBoardThickness->AddGrowableCol( 0 ); + fgSizerBoardThickness->SetFlexibleDirection( wxBOTH ); + fgSizerBoardThickness->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + boardthickness = new wxTextCtrl( sbSizerBoardThickness->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizerBoardThickness->Add( boardthickness, 0, wxALL, 5 ); + + m_spinBoardThickness = new wxSpinButton( sbSizerBoardThickness->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_VERTICAL ); + fgSizerBoardThickness->Add( m_spinBoardThickness, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + + sbSizerBoardThickness->Add( fgSizerBoardThickness, 1, wxBOTTOM|wxEXPAND|wxRIGHT, 5 ); + + + bSizerLeft->Add( sbSizerBoardThickness, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); bSizermain->Add( bSizerLeft, 0, 0, 5 ); @@ -268,6 +289,10 @@ PANEL_PREVIEW_3D_MODEL_BASE::PANEL_PREVIEW_3D_MODEL_BASE( wxWindow* parent, wxWi m_spinZoffset->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onDecrementOffset ), NULL, this ); m_spinZoffset->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onIncrementOffset ), NULL, this ); m_opacity->Connect( wxEVT_SLIDER, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onOpacitySlider ), NULL, this ); + boardthickness->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onMouseWheelBoardThickness ), NULL, this ); + boardthickness->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::updateBoardThickness ), NULL, this ); + m_spinBoardThickness->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onDecrementBoardThickness ), NULL, this ); + m_spinBoardThickness->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onIncrementBoardThickness ), NULL, this ); m_bpvISO->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::View3DISO ), NULL, this ); m_bpvLeft->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::View3DLeft ), NULL, this ); m_bpvRight->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::View3DRight ), NULL, this ); @@ -318,6 +343,10 @@ PANEL_PREVIEW_3D_MODEL_BASE::~PANEL_PREVIEW_3D_MODEL_BASE() m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onDecrementOffset ), NULL, this ); m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onIncrementOffset ), NULL, this ); m_opacity->Disconnect( wxEVT_SLIDER, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onOpacitySlider ), NULL, this ); + boardthickness->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onMouseWheelBoardThickness ), NULL, this ); + boardthickness->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::updateBoardThickness ), NULL, this ); + m_spinBoardThickness->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onDecrementBoardThickness ), NULL, this ); + m_spinBoardThickness->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::onIncrementBoardThickness ), NULL, this ); m_bpvISO->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::View3DISO ), NULL, this ); m_bpvLeft->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::View3DLeft ), NULL, this ); m_bpvRight->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL_BASE::View3DRight ), NULL, this ); diff --git a/3d-viewer/dialogs/panel_preview_3d_model_base.fbp b/3d-viewer/dialogs/panel_preview_3d_model_base.fbp index c2dd10cc1e..b7f4516efe 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model_base.fbp +++ b/3d-viewer/dialogs/panel_preview_3d_model_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -1847,7 +1847,7 @@ 5 - wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT + wxEXPAND|wxLEFT|wxRIGHT 1 wxID_ANY @@ -1925,6 +1925,164 @@ + + 5 + wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT + 0 + + wxID_ANY + Board Thickness + + sbSizerBoardThickness + wxVERTICAL + 1 + none + + 5 + wxBOTTOM|wxEXPAND|wxRIGHT + 1 + + 2 + wxBOTH + 0 + + 0 + + fgSizerBoardThickness + wxFLEX_GROWMODE_SPECIFIED + none + 0 + 0 + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + boardthickness + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + onMouseWheelBoardThickness + updateBoardThickness + + + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_spinBoardThickness + 1 + + + protected + 1 + + Resizable + 1 + + wxSP_ARROW_KEYS|wxSP_VERTICAL + ; ; forward_declare + 0 + + + + + onDecrementBoardThickness + onIncrementBoardThickness + + + + + + diff --git a/3d-viewer/dialogs/panel_preview_3d_model_base.h b/3d-viewer/dialogs/panel_preview_3d_model_base.h index 6d80d7507e..bc665c3e91 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model_base.h +++ b/3d-viewer/dialogs/panel_preview_3d_model_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Sep 12 2021) +// C++ code generated with wxFormBuilder (version 3.10.0-0-g4761b0c5) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -66,6 +66,8 @@ class PANEL_PREVIEW_3D_MODEL_BASE : public wxPanel wxTextCtrl* zoff; wxSpinButton* m_spinZoffset; wxSlider* m_opacity; + wxTextCtrl* boardthickness; + wxSpinButton* m_spinBoardThickness; wxBoxSizer* m_SizerPanelView; wxBitmapButton* m_bpvISO; wxBitmapButton* m_bpvLeft; @@ -88,6 +90,10 @@ class PANEL_PREVIEW_3D_MODEL_BASE : public wxPanel virtual void onDecrementOffset( wxSpinEvent& event ) { event.Skip(); } virtual void onIncrementOffset( wxSpinEvent& event ) { event.Skip(); } virtual void onOpacitySlider( wxCommandEvent& event ) { event.Skip(); } + virtual void onMouseWheelBoardThickness( wxMouseEvent& event ) { event.Skip(); } + virtual void updateBoardThickness( wxCommandEvent& event ) { event.Skip(); } + virtual void onDecrementBoardThickness( wxSpinEvent& event ) { event.Skip(); } + virtual void onIncrementBoardThickness( wxSpinEvent& event ) { event.Skip(); } virtual void View3DISO( wxCommandEvent& event ) { event.Skip(); } virtual void View3DLeft( wxCommandEvent& event ) { event.Skip(); } virtual void View3DRight( wxCommandEvent& event ) { event.Skip(); }