Make 3D model preview board thickness adjustable

This commit is contained in:
Simon Schaak 2021-10-10 16:41:25 +02:00 committed by Wayne Stambaugh
parent c0a666507c
commit 589f1058ca
5 changed files with 289 additions and 6 deletions

View File

@ -40,6 +40,7 @@
#include <settings/settings_manager.h>
#include <widgets/infobar.h>
#include <eda_3d_viewer_settings.h>
#include <board_design_settings.h>
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 )
{

View File

@ -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
{

View File

@ -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 );

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<FileVersion major="1" minor="16" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
@ -1847,7 +1847,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT</property>
<property name="flag">wxEXPAND|wxLEFT|wxRIGHT</property>
<property name="proportion">1</property>
<object class="wxStaticBoxSizer" expanded="1">
<property name="id">wxID_ANY</property>
@ -1925,6 +1925,164 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticBoxSizer" expanded="1">
<property name="id">wxID_ANY</property>
<property name="label">Board Thickness</property>
<property name="minimum_size"></property>
<property name="name">sbSizerBoardThickness</property>
<property name="orient">wxVERTICAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxEXPAND|wxRIGHT</property>
<property name="proportion">1</property>
<object class="wxFlexGridSizer" expanded="1">
<property name="cols">2</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols">0</property>
<property name="growablerows"></property>
<property name="hgap">0</property>
<property name="minimum_size"></property>
<property name="name">fgSizerBoardThickness</property>
<property name="non_flexible_grow_mode">wxFLEX_GROWMODE_SPECIFIED</property>
<property name="permission">none</property>
<property name="rows">0</property>
<property name="vgap">0</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">boardthickness</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnMouseWheel">onMouseWheelBoardThickness</event>
<event name="OnText">updateBoardThickness</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxSpinButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_spinBoardThickness</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxSP_ARROW_KEYS|wxSP_VERTICAL</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnSpinDown">onDecrementBoardThickness</event>
<event name="OnSpinUp">onIncrementBoardThickness</event>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -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(); }